mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
Fix parsing of class member named declare (#822)
This commit is contained in:
parent
c7e4783837
commit
d82e6ab69d
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "swc_ecma_parser"
|
||||
version = "0.24.4"
|
||||
version = "0.24.5"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
license = "Apache-2.0/MIT"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
|
@ -299,7 +299,55 @@ impl<'a, I: Tokens> Parser<'a, I> {
|
||||
let decorators = self.parse_decorators(false)?;
|
||||
|
||||
if self.syntax().typescript() && eat!("declare") {
|
||||
self.emit_err(make_span(self.input.prev_span()), SyntaxError::TS1031);
|
||||
let accessibility = if self.input.syntax().typescript() {
|
||||
self.parse_access_modifier()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Handle declare(){}
|
||||
if self.is_class_method()? {
|
||||
let key = Either::Right(PropName::Ident(Ident::new(
|
||||
js_word!("declare"),
|
||||
span!(start),
|
||||
)));
|
||||
let is_optional = self.input.syntax().typescript() && eat!('?');
|
||||
return self.make_method(
|
||||
|p| p.parse_unique_formal_params(),
|
||||
MakeMethodArgs {
|
||||
start,
|
||||
accessibility,
|
||||
decorators,
|
||||
is_abstract: false,
|
||||
is_optional,
|
||||
is_async: false,
|
||||
is_generator: false,
|
||||
static_token: None,
|
||||
key,
|
||||
kind: MethodKind::Method,
|
||||
},
|
||||
);
|
||||
} else if self.is_class_property()? {
|
||||
// Property named `declare`
|
||||
|
||||
let key = Either::Right(PropName::Ident(Ident::new(
|
||||
js_word!("declare"),
|
||||
span!(start),
|
||||
)));
|
||||
let is_optional = self.input.syntax().typescript() && eat!('?');
|
||||
return self.make_property(
|
||||
start,
|
||||
decorators,
|
||||
accessibility,
|
||||
key,
|
||||
false,
|
||||
is_optional,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
self.emit_err(make_span(self.input.prev_span()), SyntaxError::TS1031);
|
||||
}
|
||||
}
|
||||
|
||||
let accessibility = if self.input.syntax().typescript() {
|
||||
|
3
ecmascript/parser/tests/jsx/basic/issue-812/input.js
Normal file
3
ecmascript/parser/tests/jsx/basic/issue-812/input.js
Normal file
@ -0,0 +1,3 @@
|
||||
class A {
|
||||
declare() {}
|
||||
}
|
85
ecmascript/parser/tests/jsx/basic/issue-812/input.js.json
Normal file
85
ecmascript/parser/tests/jsx/basic/issue-812/input.js.json
Normal file
@ -0,0 +1,85 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"identifier": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 6,
|
||||
"end": 7,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "A",
|
||||
"typeAnnotation": null,
|
||||
"optional": false
|
||||
},
|
||||
"declare": false,
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
"decorators": [],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "declare",
|
||||
"typeAnnotation": null,
|
||||
"optional": false
|
||||
},
|
||||
"function": {
|
||||
"params": [],
|
||||
"decorators": [],
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"span": {
|
||||
"start": 24,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"stmts": []
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"typeParameters": null,
|
||||
"returnType": null
|
||||
},
|
||||
"kind": "method",
|
||||
"isStatic": false,
|
||||
"accessibility": null,
|
||||
"isAbstract": false,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"superClass": null,
|
||||
"isAbstract": false,
|
||||
"typeParams": null,
|
||||
"superTypeParams": null,
|
||||
"implements": []
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
3
ecmascript/parser/tests/typescript/issue-812/input.ts
Normal file
3
ecmascript/parser/tests/typescript/issue-812/input.ts
Normal file
@ -0,0 +1,3 @@
|
||||
class A {
|
||||
declare() {}
|
||||
}
|
85
ecmascript/parser/tests/typescript/issue-812/input.ts.json
Normal file
85
ecmascript/parser/tests/typescript/issue-812/input.ts.json
Normal file
@ -0,0 +1,85 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"identifier": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 6,
|
||||
"end": 7,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "A",
|
||||
"typeAnnotation": null,
|
||||
"optional": false
|
||||
},
|
||||
"declare": false,
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 28,
|
||||
"ctxt": 0
|
||||
},
|
||||
"decorators": [],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 21,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "declare",
|
||||
"typeAnnotation": null,
|
||||
"optional": false
|
||||
},
|
||||
"function": {
|
||||
"params": [],
|
||||
"decorators": [],
|
||||
"span": {
|
||||
"start": 14,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"span": {
|
||||
"start": 24,
|
||||
"end": 26,
|
||||
"ctxt": 0
|
||||
},
|
||||
"stmts": []
|
||||
},
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"typeParameters": null,
|
||||
"returnType": null
|
||||
},
|
||||
"kind": "method",
|
||||
"isStatic": false,
|
||||
"accessibility": null,
|
||||
"isAbstract": false,
|
||||
"isOptional": false
|
||||
}
|
||||
],
|
||||
"superClass": null,
|
||||
"isAbstract": false,
|
||||
"typeParams": null,
|
||||
"superTypeParams": null,
|
||||
"implements": []
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
Loading…
Reference in New Issue
Block a user