Skip to content

Commit

Permalink
fix(lexer): fixed ZWJ issue in identifierPart validation
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 26, 2019
1 parent 81b5bbc commit 3708214
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/lexer/charClassifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { unicodeLookup } from '../unicode';
import { Chars } from '../chars';

export const enum CharFlags {
None = 0,
Expand Down Expand Up @@ -168,7 +169,7 @@ export function isIdentifierStart(code: number): number {
: (unicodeLookup[(code >>> 5) + 34816] >>> code) & 31 & 1;
}

export function isIdentifierPart(code: number): number {
export function isIdentifierPart(code: number): any {
/*
* ES2020 11.6 IdentifierPart
* $ (dollar sign)
Expand All @@ -181,5 +182,5 @@ export function isIdentifierPart(code: number): number {
*/
return code <= 0x7F
? CharTypes[code] & CharFlags.IdentifierPart
: (unicodeLookup[(code >>> 5) + 0] >>> code) & 31 & 1;
: (unicodeLookup[(code >>> 5) + 0] >>> code) & 31 & 1 || (code === Chars.ZeroWidthJoiner || code === Chars.ZeroWidthNonJoiner);
}
2 changes: 1 addition & 1 deletion test/parser/miscellaneous/pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2925,7 +2925,7 @@ if (a) {
a();
} while (false);
}());`,
// `T‍ = []`,
`T‍ = []`,
`function a(b, c) {
function d() {
e();
Expand Down
4 changes: 1 addition & 3 deletions test/parser/next/private_methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('Next - Private methods', () => {
['class A { #x; x() { delete ((this.#m )); } async #m() {} }', Context.OptionsNext],
['class A { # x }', Context.OptionsNext],
['class A { #\\u0000; }', Context.OptionsNext],
['class A { #\\u200D_ZWJ;; }', Context.OptionsNext],
['class A { * # m() {} }', Context.OptionsNext],
['class A { # x; }', Context.OptionsNext],
['class A { #x; m() { this.# x; }}', Context.OptionsNext],
Expand Down Expand Up @@ -106,8 +105,7 @@ describe('Next - Private methods', () => {
'static #x = /*{ initializer }*/;',
'#x = () => super();',
'#x = super();',
'#\\u0000;',
'#\\u200D_ZWJ;'
'#\\u0000;'
]) {
it(`class C { ${arg} }`, () => {
t.throws(() => {
Expand Down

0 comments on commit 3708214

Please sign in to comment.