mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 04:39:06 +03:00
fix(swc): Fix bugs (#1591)
swc_ecma_parser: - Support optional async class methods. (#1454) swc_ecma_transforms_compat: - Hoist import statements. (#1457)
This commit is contained in:
parent
1c4fa63bdc
commit
dbec753ca1
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_parser"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.54.3"
|
||||
version = "0.54.4"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -718,6 +718,7 @@ impl<'a, I: Tokens> Parser<I> {
|
||||
}
|
||||
|
||||
// handle async foo(){}
|
||||
let is_optional = is_optional || self.input.syntax().typescript() && eat!(self, '?');
|
||||
return self.make_method(
|
||||
|p| p.parse_unique_formal_params(),
|
||||
MakeMethodArgs {
|
||||
|
@ -0,0 +1,4 @@
|
||||
export abstract class AbstractProviderDeliveryService {
|
||||
// legal typescript method annotation
|
||||
async prepareGetRequest?(): Promise<any>;
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 145,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDeclaration",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 145,
|
||||
"ctxt": 0
|
||||
},
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"identifier": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 22,
|
||||
"end": 53,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AbstractProviderDeliveryService",
|
||||
"optional": false
|
||||
},
|
||||
"declare": false,
|
||||
"span": {
|
||||
"start": 7,
|
||||
"end": 145,
|
||||
"ctxt": 0
|
||||
},
|
||||
"decorators": [],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"span": {
|
||||
"start": 102,
|
||||
"end": 143,
|
||||
"ctxt": 0
|
||||
},
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 108,
|
||||
"end": 125,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "prepareGetRequest",
|
||||
"optional": false
|
||||
},
|
||||
"function": {
|
||||
"params": [],
|
||||
"decorators": [],
|
||||
"span": {
|
||||
"start": 102,
|
||||
"end": 143,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"typeParameters": null,
|
||||
"returnType": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 128,
|
||||
"end": 142,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeReference",
|
||||
"span": {
|
||||
"start": 130,
|
||||
"end": 142,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeName": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 130,
|
||||
"end": 137,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "Promise",
|
||||
"optional": false
|
||||
},
|
||||
"typeParams": {
|
||||
"type": "TsTypeParameterInstantiation",
|
||||
"span": {
|
||||
"start": 137,
|
||||
"end": 142,
|
||||
"ctxt": 0
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "TsKeywordType",
|
||||
"span": {
|
||||
"start": 138,
|
||||
"end": 141,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"kind": "method",
|
||||
"isStatic": false,
|
||||
"accessibility": null,
|
||||
"isAbstract": false,
|
||||
"isOptional": true,
|
||||
"isOverride": false
|
||||
}
|
||||
],
|
||||
"superClass": null,
|
||||
"isAbstract": true,
|
||||
"typeParams": null,
|
||||
"superTypeParams": null,
|
||||
"implements": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export abstract class AbstractProviderDeliveryService {
|
||||
// legal typescript method annotation
|
||||
async prepareGetRequest(): Promise<any>;
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
{
|
||||
"type": "Module",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 144,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ExportDeclaration",
|
||||
"span": {
|
||||
"start": 0,
|
||||
"end": 144,
|
||||
"ctxt": 0
|
||||
},
|
||||
"declaration": {
|
||||
"type": "ClassDeclaration",
|
||||
"identifier": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 22,
|
||||
"end": 53,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "AbstractProviderDeliveryService",
|
||||
"optional": false
|
||||
},
|
||||
"declare": false,
|
||||
"span": {
|
||||
"start": 7,
|
||||
"end": 144,
|
||||
"ctxt": 0
|
||||
},
|
||||
"decorators": [],
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassMethod",
|
||||
"span": {
|
||||
"start": 102,
|
||||
"end": 142,
|
||||
"ctxt": 0
|
||||
},
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 108,
|
||||
"end": 125,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "prepareGetRequest",
|
||||
"optional": false
|
||||
},
|
||||
"function": {
|
||||
"params": [],
|
||||
"decorators": [],
|
||||
"span": {
|
||||
"start": 102,
|
||||
"end": 142,
|
||||
"ctxt": 0
|
||||
},
|
||||
"body": null,
|
||||
"generator": false,
|
||||
"async": true,
|
||||
"typeParameters": null,
|
||||
"returnType": {
|
||||
"type": "TsTypeAnnotation",
|
||||
"span": {
|
||||
"start": 127,
|
||||
"end": 141,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeAnnotation": {
|
||||
"type": "TsTypeReference",
|
||||
"span": {
|
||||
"start": 129,
|
||||
"end": 141,
|
||||
"ctxt": 0
|
||||
},
|
||||
"typeName": {
|
||||
"type": "Identifier",
|
||||
"span": {
|
||||
"start": 129,
|
||||
"end": 136,
|
||||
"ctxt": 0
|
||||
},
|
||||
"value": "Promise",
|
||||
"optional": false
|
||||
},
|
||||
"typeParams": {
|
||||
"type": "TsTypeParameterInstantiation",
|
||||
"span": {
|
||||
"start": 136,
|
||||
"end": 141,
|
||||
"ctxt": 0
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "TsKeywordType",
|
||||
"span": {
|
||||
"start": 137,
|
||||
"end": 140,
|
||||
"ctxt": 0
|
||||
},
|
||||
"kind": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"kind": "method",
|
||||
"isStatic": false,
|
||||
"accessibility": null,
|
||||
"isAbstract": false,
|
||||
"isOptional": false,
|
||||
"isOverride": false
|
||||
}
|
||||
],
|
||||
"superClass": null,
|
||||
"isAbstract": true,
|
||||
"typeParams": null,
|
||||
"superTypeParams": null,
|
||||
"implements": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"interpreter": null
|
||||
}
|
@ -73,7 +73,7 @@ impl Fold for ExportNamespaceFrom {
|
||||
extra_stmts.push(ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(export)));
|
||||
}
|
||||
}
|
||||
ModuleItem::ModuleDecl(ModuleDecl::Import(..)) => extra_stmts.push(item),
|
||||
ModuleItem::ModuleDecl(ModuleDecl::Import(..)) => stmts.push(item),
|
||||
_ => extra_stmts.push(item),
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_utils"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.34.1"
|
||||
version = "0.34.2"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
24
tests/fixture/issue-1454/case2/input/.swcrc
Normal file
24
tests/fixture/issue-1454/case2/input/.swcrc
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"test": ".*.ts$",
|
||||
"jsc": {
|
||||
"loose": true,
|
||||
"target": "es2018",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": false,
|
||||
"decorators": true,
|
||||
"dynamicImport": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": true
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs",
|
||||
"strict": true,
|
||||
"strictMode": false,
|
||||
"lazy": false,
|
||||
"noInterop": false
|
||||
}
|
||||
}
|
2
tests/fixture/issue-1454/case2/input/index.ts
Normal file
2
tests/fixture/issue-1454/case2/input/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export abstract class AbstractProviderDeliveryService {
|
||||
}
|
3
tests/fixture/issue-1454/case2/output/index.ts
Normal file
3
tests/fixture/issue-1454/case2/output/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
class AbstractProviderDeliveryService {
|
||||
}
|
||||
exports.AbstractProviderDeliveryService = AbstractProviderDeliveryService;
|
4
tests/fixture/issue-1454/case3/input/index.ts
Normal file
4
tests/fixture/issue-1454/case3/input/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export abstract class AbstractProviderDeliveryService {
|
||||
// legal typescript method annotation
|
||||
async prepareGetRequest?(): Promise<any>;
|
||||
}
|
9
tests/fixture/issue-1454/case3/output/index.ts
Normal file
9
tests/fixture/issue-1454/case3/output/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
export var AbstractProviderDeliveryService = function AbstractProviderDeliveryService() {
|
||||
"use strict";
|
||||
_classCallCheck(this, AbstractProviderDeliveryService);
|
||||
};
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { setGlobalOptions } from '@typegoose/typegoose';
|
||||
import * as typegoose from '@typegoose/typegoose';
|
||||
import { schemas } from './schemas';
|
||||
// typegoose.mongoose.set('debug', true);
|
||||
setGlobalOptions({
|
||||
options: {
|
||||
@ -12,5 +13,4 @@ setGlobalOptions({
|
||||
}
|
||||
}
|
||||
});
|
||||
import { schemas } from './schemas';
|
||||
console.log(schemas);
|
||||
|
Loading…
Reference in New Issue
Block a user