Skip to content

Commit 740e6f3

Browse files
authoredJan 4, 2024
fix(es/parser): Correctly parse the keyword (#8483)
**Related issue:** - Closes #8482.
1 parent 4e860c9 commit 740e6f3

File tree

7 files changed

+112
-7
lines changed

7 files changed

+112
-7
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "ecmascript",
5+
"jsx": false
6+
},
7+
"externalHelpers": true,
8+
"minify": {
9+
"compress": false,
10+
"mangle": false
11+
},
12+
"keepClassNames": true,
13+
"loose": true
14+
},
15+
"minify": false,
16+
"isModule": true,
17+
"module": {
18+
"type": "umd"
19+
},
20+
"env": {
21+
"targets": "",
22+
"bugfixes": true
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let a = ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(function(global, factory) {
2+
if (typeof module === "object" && typeof module.exports === "object") factory(exports);
3+
else if (typeof define === "function" && define.amd) define([
4+
"exports"
5+
], factory);
6+
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.index = {});
7+
})(this, function(exports) {
8+
"use strict";
9+
Object.defineProperty(exports, "__esModule", {
10+
value: true
11+
});
12+
Object.defineProperty(exports, "a", {
13+
enumerable: true,
14+
get: function() {
15+
return a;
16+
}
17+
});
18+
let a = "";
19+
});

‎crates/swc_ecma_parser/src/lexer/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,16 @@ impl<'a> Lexer<'a> {
824824
// Optimization
825825
{
826826
let s = l.input.uncons_while(|c| {
827+
if !c.is_ident_part() {
828+
return false;
829+
}
830+
827831
// Performance optimization
828832
if c.is_ascii_uppercase() || c.is_ascii_digit() || !c.is_ascii() {
829833
can_be_keyword = false;
830834
}
831835

832-
c.is_ident_part()
836+
true
833837
});
834838
if !s.is_empty() {
835839
first = false;

‎crates/swc_ecma_parser/src/lexer/table.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,7 @@ const L_I: ByteHandler = Some(|lexer| {
153153
})
154154
});
155155

156-
const L_J: ByteHandler = Some(|lexer| {
157-
lexer.read_word_with(|s| match s {
158-
"let" => Some(Word::Keyword(Keyword::Let)),
159-
_ => None,
160-
})
161-
});
156+
const L_J: ByteHandler = IDN;
162157

163158
const L_K: ByteHandler = Some(|lexer| {
164159
lexer.read_word_with(|s| match s {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let a = ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"type": "Module",
3+
"span": {
4+
"start": 1,
5+
"end": 19,
6+
"ctxt": 0
7+
},
8+
"body": [
9+
{
10+
"type": "ExportDeclaration",
11+
"span": {
12+
"start": 1,
13+
"end": 19,
14+
"ctxt": 0
15+
},
16+
"declaration": {
17+
"type": "VariableDeclaration",
18+
"span": {
19+
"start": 8,
20+
"end": 19,
21+
"ctxt": 0
22+
},
23+
"kind": "let",
24+
"declare": false,
25+
"declarations": [
26+
{
27+
"type": "VariableDeclarator",
28+
"span": {
29+
"start": 13,
30+
"end": 19,
31+
"ctxt": 0
32+
},
33+
"id": {
34+
"type": "Identifier",
35+
"span": {
36+
"start": 13,
37+
"end": 14,
38+
"ctxt": 0
39+
},
40+
"value": "a",
41+
"optional": false,
42+
"typeAnnotation": null
43+
},
44+
"init": {
45+
"type": "StringLiteral",
46+
"span": {
47+
"start": 17,
48+
"end": 19,
49+
"ctxt": 0
50+
},
51+
"value": "",
52+
"raw": "''"
53+
},
54+
"definite": false
55+
}
56+
]
57+
}
58+
}
59+
],
60+
"interpreter": null
61+
}

0 commit comments

Comments
 (0)
Please sign in to comment.