fix(es): Fix bugs (#2256)

swc_ecma_codegen:
 - Fix source map of string literals. (#2253)

swc_ecma_transforms_typescript:
 - Allow using same name for a module with function. (#2243)
This commit is contained in:
강동윤 2021-09-18 16:52:08 +09:00 committed by GitHub
parent f087d1515b
commit ce01b8a9b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 140 additions and 14 deletions

6
Cargo.lock generated
View File

@ -2557,7 +2557,7 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_codegen" name = "swc_ecma_codegen"
version = "0.70.3" version = "0.70.4"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"num-bigint", "num-bigint",
@ -2922,7 +2922,7 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_transforms_typescript" name = "swc_ecma_transforms_typescript"
version = "0.40.3" version = "0.40.4"
dependencies = [ dependencies = [
"fxhash", "fxhash",
"serde", "serde",
@ -3401,7 +3401,7 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]] [[package]]
name = "wasm" name = "wasm"
version = "1.2.88" version = "1.2.89"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"console_error_panic_hook", "console_error_panic_hook",

View File

@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT" license = "Apache-2.0/MIT"
name = "swc_ecma_codegen" name = "swc_ecma_codegen"
repository = "https://github.com/swc-project/swc.git" repository = "https://github.com/swc-project/swc.git"
version = "0.70.3" version = "0.70.4"
[dependencies] [dependencies]
bitflags = "1" bitflags = "1"

View File

@ -434,12 +434,12 @@ impl<'a> Emitter<'a> {
}; };
if single_quote { if single_quote {
punct!("'"); punct!(node.span, "'");
self.wr.write_str_lit(node.span, &value)?; self.wr.write_str_lit(DUMMY_SP, &value)?;
punct!("'"); punct!("'");
} else { } else {
punct!("\""); punct!(node.span, "\"");
self.wr.write_str_lit(node.span, &value)?; self.wr.write_str_lit(DUMMY_SP, &value)?;
punct!("\""); punct!("\"");
} }
} }

View File

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT" license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_typescript" name = "swc_ecma_transforms_typescript"
repository = "https://github.com/swc-project/swc.git" repository = "https://github.com/swc-project/swc.git"
version = "0.40.3" version = "0.40.4"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]

View File

@ -1181,7 +1181,10 @@ impl Visit for Strip {
self.decl_names.insert(class.ident.to_id()); self.decl_names.insert(class.ident.to_id());
class.class.visit_with(class, self); class.class.visit_with(class, self);
} }
Decl::Fn(f) => f.function.visit_with(f, self), Decl::Fn(f) => {
self.decl_names.insert(f.ident.to_id());
f.function.visit_with(f, self)
}
Decl::Var(ref var) => { Decl::Var(ref var) => {
for decl in &var.decls { for decl in &var.decls {
self.in_var_pat = true; self.in_var_pat = true;

View File

@ -1,3 +1,5 @@
export type Colors = 0.0 | 1.0 | 2.0;
export function Colors(member: Colors.KeyType): Colors { export function Colors(member: Colors.KeyType): Colors {
return Colors.ValueFor(member); return Colors.ValueFor(member);
} }
@ -17,7 +19,7 @@ export module Colors {
return ValueMap[member]?.value; return ValueMap[member]?.value;
} }
export function LabelFor( export async function LabelFor(
member: KeyType member: KeyType
): Promise<string | undefined> { ): Promise<string | undefined> {
return ValueMap[member]?.label; return ValueMap[member]?.label;

View File

@ -0,0 +1,33 @@
export function Colors(member) {
return Colors.ValueFor(member);
}
(function(Colors) {
Colors.ValueMap = {
Red: {
value: 0,
label: "Red"
},
Blue: {
value: 1,
label: "Blue"
},
Green: {
value: 2,
label: "Green"
}
};
Colors.Values = [
0,
1,
2
];
function ValueFor(member) {
return ValueMap[member]?.value;
}
Colors.ValueFor = ValueFor;
async function LabelFor(member) {
return ValueMap[member]?.label;
}
Colors.LabelFor = LabelFor;
})(Colors || (Colors = {
}));

View File

@ -1,6 +1,6 @@
{ {
"name": "@swc/core", "name": "@swc/core",
"version": "1.2.88", "version": "1.2.89",
"description": "Super-fast alternative for babel", "description": "Super-fast alternative for babel",
"homepage": "https://swc.rs", "homepage": "https://swc.rs",
"main": "./index.js", "main": "./index.js",

View File

@ -1,5 +1,5 @@
{ {
"mappings": "QAAO,WAAa;SAEX,CAAC,GAAG,CAAC;IACV,CAAC;AACL,CAAC;SAEQ,CAAC,CAAC,KAAS,EAAE,CAAC;QAAZ,CAAC,GAAD,KAAS,cAAL,KAAK,GAAT,KAAS;IAChB,EAAE,EAAE,CAAC,EAAE,CAAC;QACJ,KAAK,CAAC,GAAG,CAAC,KAAK,EAAC,KAAO;IAC3B,CAAC;IACD,CAAC,EAAE,CAAC;AACR,CAAC;AAED,CAAC", "mappings": "OAAO,CAAa;SAEX,CAAC,GAAG,CAAC;IACV,CAAC;AACL,CAAC;SAEQ,CAAC,CAAC,KAAS,EAAE,CAAC;QAAZ,CAAC,GAAD,KAAS,cAAL,KAAK,GAAT,KAAS;IAChB,EAAE,EAAE,CAAC,EAAE,CAAC;QACJ,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAO;IAC3B,CAAC;IACD,CAAC,EAAE,CAAC;AACR,CAAC;AAED,CAAC",
"names": [ "names": [
"a", "a",
"t", "t",

View File

@ -0,0 +1,9 @@
const resolver = {
async sendSomeMessage(
_parent: unknown,
{ input: { toNumber, messageBody, ...all } }: SendSomeMessageInput,
{ dataSources }: Context,
): Promise<boolean> { }
}
export default resolver

View File

@ -0,0 +1,79 @@
import regeneratorRuntime from "regenerator-runtime";
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {
};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {
};
var target = {
};
var sourceKeys = Object.keys(source);
var key, i;
for(i = 0; i < sourceKeys.length; i++){
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
var resolver = {
sendSomeMessage: function(_parent, _param, _param1) {
return _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
var toNumber, messageBody, all, dataSources;
return regeneratorRuntime.wrap(function _callee$(_ctx) {
var ref;
while(1)switch(_ctx.prev = _ctx.next){
case 0:
var ref1, ref2;
ref1 = _param, ref = ref1.input, toNumber = ref.toNumber, messageBody = ref.messageBody, ref, ref1, all = _objectWithoutProperties(_param.input, ["toNumber", "messageBody"]), ref2 = _param1, dataSources = ref2.dataSources, ref2;
case 1:
case "end":
return _ctx.stop();
}
}, _callee);
}))();
}
};
export default resolver;

View File

@ -6,7 +6,7 @@ license = "Apache-2.0 AND MIT"
name = "wasm" name = "wasm"
publish = false publish = false
repository = "https://github.com/swc-project/swc.git" repository = "https://github.com/swc-project/swc.git"
version = "1.2.88" version = "1.2.89"
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["cdylib"]