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:
강동윤 2021-04-21 09:26:07 +09:00 committed by GitHub
parent 1c4fa63bdc
commit dbec753ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 318 additions and 11 deletions

View File

@ -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 = []

View File

@ -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 {

View File

@ -0,0 +1,4 @@
export abstract class AbstractProviderDeliveryService {
// legal typescript method annotation
async prepareGetRequest?(): Promise<any>;
}

View File

@ -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
}

View File

@ -0,0 +1,4 @@
export abstract class AbstractProviderDeliveryService {
// legal typescript method annotation
async prepareGetRequest(): Promise<any>;
}

View File

@ -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
}

View File

@ -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),
}
}

View File

@ -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

View 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
}
}

View File

@ -0,0 +1,2 @@
export abstract class AbstractProviderDeliveryService {
}

View File

@ -0,0 +1,3 @@
class AbstractProviderDeliveryService {
}
exports.AbstractProviderDeliveryService = AbstractProviderDeliveryService;

View File

@ -0,0 +1,4 @@
export abstract class AbstractProviderDeliveryService {
// legal typescript method annotation
async prepareGetRequest?(): Promise<any>;
}

View 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);
};

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);