mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
fix(es/parser): Correctly parse the keyword (#8483)
**Related issue:** - Closes #8482.
This commit is contained in:
parent
4e860c988d
commit
740e6f390a
24
crates/swc/tests/fixture/issues-8xxx/8482/input/.swcrc
Normal file
24
crates/swc/tests/fixture/issues-8xxx/8482/input/.swcrc
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"jsx": false
|
||||
},
|
||||
"externalHelpers": true,
|
||||
"minify": {
|
||||
"compress": false,
|
||||
"mangle": false
|
||||
},
|
||||
"keepClassNames": true,
|
||||
"loose": true
|
||||
},
|
||||
"minify": false,
|
||||
"isModule": true,
|
||||
"module": {
|
||||
"type": "umd"
|
||||
},
|
||||
"env": {
|
||||
"targets": "",
|
||||
"bugfixes": true
|
||||
}
|
||||
}
|
1
crates/swc/tests/fixture/issues-8xxx/8482/input/index.js
Normal file
1
crates/swc/tests/fixture/issues-8xxx/8482/input/index.js
Normal file
@ -0,0 +1 @@
|
||||
export let a = ''
|
19
crates/swc/tests/fixture/issues-8xxx/8482/output/index.js
Normal file
19
crates/swc/tests/fixture/issues-8xxx/8482/output/index.js
Normal file
@ -0,0 +1,19 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory(exports);
|
||||
else if (typeof define === "function" && define.amd) define([
|
||||
"exports"
|
||||
], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.index = {});
|
||||
})(this, function(exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "a", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return a;
|
||||
}
|
||||
});
|
||||
let a = "";
|
||||
});
|
@ -824,12 +824,16 @@ impl<'a> Lexer<'a> {
|
||||
// Optimization
|
||||
{
|
||||
let s = l.input.uncons_while(|c| {
|
||||
if !c.is_ident_part() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Performance optimization
|
||||
if c.is_ascii_uppercase() || c.is_ascii_digit() || !c.is_ascii() {
|
||||
can_be_keyword = false;
|
||||
}
|
||||
|
||||
c.is_ident_part()
|
||||
true
|
||||
});
|
||||
if !s.is_empty() {
|
||||
first = false;
|
||||
|
@ -153,12 +153,7 @@ const L_I: ByteHandler = Some(|lexer| {
|
||||
})
|
||||
});
|
||||
|
||||
const L_J: ByteHandler = Some(|lexer| {
|
||||
lexer.read_word_with(|s| match s {
|
||||
"let" => Some(Word::Keyword(Keyword::Let)),
|
||||
_ => None,
|
||||
})
|
||||
});
|
||||
const L_J: ByteHandler = IDN;
|
||||
|
||||
const L_K: ByteHandler = Some(|lexer| {
|
||||
lexer.read_word_with(|s| match s {
|
||||
|
1
crates/swc_ecma_parser/tests/js/issue-8482/input.js
Normal file
1
crates/swc_ecma_parser/tests/js/issue-8482/input.js
Normal file
@ -0,0 +1 @@
|
||||
export let a = ''
|
61
crates/swc_ecma_parser/tests/js/issue-8482/input.js.json
Normal file
61
crates/swc_ecma_parser/tests/js/issue-8482/input.js.json
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDeclaration",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"declaration": {
|
||||
"type": "VariableDeclaration",
|
||||
"span": {
|
||||
"start": 8,
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "let",
|
||||
"declare": false,
|
||||
"declarations": [
|
||||
{
|
||||
"type": "VariableDeclarator",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 13,
|
||||
"end": 14,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "a",
|
||||
"optional": false,
|
||||
"typeAnnotation": null
|
||||
},
|
||||
"init": {
|
||||
"type": "StringLiteral",
|
||||
"span": {
|
||||
"start": 17,
|
||||
"end": 19,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "",
|
||||
"raw": "''"
|
||||
},
|
||||
"definite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
Loading…
Reference in New Issue
Block a user