TyrealHu / acorn-typescript

Alternative, TypeScript parser
https://www.npmjs.com/package/acorn-typescript?activeTab=readme
MIT License
145 stars 18 forks source link

`this` variable declarations should cause an error. #23

Open ota-meshi opened 1 year ago

ota-meshi commented 1 year ago

It seems that an error should be raised in the following cases, but the error is not raised. I found this from test262 results.

// See: https://github.com/tc39/test262/blob/main/test/language/identifiers/val-this.js
var this = 42;

// See: https://github.com/tc39/test262/blob/main/test/language/statements/class/syntax/escaped-static.js
class C {
  st\u0061tic m() {
  } 
}
ota-meshi commented 1 year ago

I believe #25 fixes the escaped static keyword.

TyrealHu commented 1 year ago

we wont handle this in acorn-typescript. bo this may be a parameter in typescript

ota-meshi commented 1 year ago

Yeah, TypeScript allows we to use this for parameters, but it is still an error to use this for variable declarations.

https://www.typescriptlang.org/play?#code/G4QwTgBALgFglgZwgXggFgEwCgsDMCuAdgMZRwD2h05AogB4AOlApoWSADYAUsiAXBEL4AtgCNmYAJQQA3lggQwzKPjBVeCAHRRajFmzicukrAF8sQA

TyrealHu commented 1 year ago

Yeah, That's an error in typescript. Parse this in parameter will call parseBindingAtom, and then call the parseIdent to parse it. Parse this in val decl will alse call the parseBindingAtom. So its so hard for us to distinguish which is in parameter or val decl

ota-meshi commented 1 year ago

I agree that it is hard. At least I didn't think I could fix it, so I left it as an issue.