fix(es/parser): Correctly parse the keyword (#8483)

**Related issue:**

 - Closes #8482.
This commit is contained in:
magic-akari 2024-01-04 20:26:25 +08:00 committed by GitHub
parent 4e860c988d
commit 740e6f390a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 7 deletions

View 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
}
}

View File

@ -0,0 +1 @@
export let a = ''

View 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 = "";
});

View File

@ -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;

View File

@ -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 {

View File

@ -0,0 +1 @@
export let a = ''

View 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
}