boa icon indicating copy to clipboard operation
boa copied to clipboard

Reserved word (keyword) as identifier and object properties

Open jevancc opened this issue 4 years ago • 3 comments

Describe the bug Boa throws syntax error when using some reserved words as variable names, function arguments, and object property.

To Reproduce

let o = { false: 100 };
o.false; // syntax error, should work

Another related bug:

function f(await, x) { 
     return await + x; // syntax error, should work
}
f(1, 2);

After the Unicode escapes in identifier name are supported, the following code should also work properly:

let o = { f\u{61}lse: 10}; // should work
o.f\u{61}lse; // should work

let x = f\u{61}lse; // should throw syntax error, keyword cannot contain unicode escapes

Expected behavior As mentioned above.

Additional context The Identifier syntax defined in ECMAscript is not properly implemented. Reference: https://tc39.es/ecma262/#sec-identifiers

jevancc avatar Feb 05 '21 01:02 jevancc

I am working on this issue.

The Unicode escape in identifier name (lexer) is supported in #1102 , but this issue seems to be a bug across both the lexer and parser - the keyword should be evaluated in parser based on where it appears instead of the lexer. I will create a separate PR for it since it will be big and it is more suitable to be addressed the bug separately.

jevancc avatar Feb 05 '21 01:02 jevancc

I am working on this issue.

The Unicode escape in identifier name (lexer) is supported in #1102 , but this issue seems to be a bug across both the lexer and parser - the keyword should be evaluated in parser based on where it appears instead of the lexer. I will create a separate PR for it since it will be big and it is more suitable to be addressed the bug separately.

Is this fixed now?

Razican avatar Jan 31 '22 10:01 Razican

The first example still throws a syntax error. The second throws no errors. The third example incorrectly errors for the first two lines.

lupd avatar Apr 09 '22 01:04 lupd

Everything has been solved, except for the last line:

let x = f\u{61}lse; // should throw syntax error, keyword cannot contain unicode escapes

I'm closing this issue and I will open a new one to specifically track that case.

Razican avatar Mar 31 '23 13:03 Razican