diff --git a/crates/swc/tests/fixture/issues-8xxx/8482/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8482/input/.swcrc new file mode 100644 index 000000000000..0f938d965fd6 --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8482/input/.swcrc @@ -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 + } +} diff --git a/crates/swc/tests/fixture/issues-8xxx/8482/input/index.js b/crates/swc/tests/fixture/issues-8xxx/8482/input/index.js new file mode 100644 index 000000000000..0787f666c0ea --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8482/input/index.js @@ -0,0 +1 @@ +export let a = '' \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-8xxx/8482/output/index.js b/crates/swc/tests/fixture/issues-8xxx/8482/output/index.js new file mode 100644 index 000000000000..d056410bb6cd --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8482/output/index.js @@ -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 = ""; +}); diff --git a/crates/swc_ecma_parser/src/lexer/mod.rs b/crates/swc_ecma_parser/src/lexer/mod.rs index cd3f03d79491..61eb37df48d1 100644 --- a/crates/swc_ecma_parser/src/lexer/mod.rs +++ b/crates/swc_ecma_parser/src/lexer/mod.rs @@ -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; diff --git a/crates/swc_ecma_parser/src/lexer/table.rs b/crates/swc_ecma_parser/src/lexer/table.rs index 04e8e67c0202..a8ee7a4e8b82 100644 --- a/crates/swc_ecma_parser/src/lexer/table.rs +++ b/crates/swc_ecma_parser/src/lexer/table.rs @@ -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 { diff --git a/crates/swc_ecma_parser/tests/js/issue-8482/input.js b/crates/swc_ecma_parser/tests/js/issue-8482/input.js new file mode 100644 index 000000000000..0787f666c0ea --- /dev/null +++ b/crates/swc_ecma_parser/tests/js/issue-8482/input.js @@ -0,0 +1 @@ +export let a = '' \ No newline at end of file diff --git a/crates/swc_ecma_parser/tests/js/issue-8482/input.js.json b/crates/swc_ecma_parser/tests/js/issue-8482/input.js.json new file mode 100644 index 000000000000..85fe8a0db50b --- /dev/null +++ b/crates/swc_ecma_parser/tests/js/issue-8482/input.js.json @@ -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 +}