fix(es/modules): Fix span of imports (#3418)

swc_ecma_transforms_module:
 - `common_js`: Use original span with the syntax conext of an import specifier.
This commit is contained in:
Donny/강동윤 2022-02-01 22:37:42 +09:00 committed by GitHub
parent 2504f041f7
commit 2c99ca1bab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,21 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"target": "es2020",
"loose": true,
"transform": {
"legacyDecorator": true,
"hidden": {
"jest": true
}
}
},
"module": {
"type": "commonjs"
},
"minify": false,
"sourceMaps": "inline"
}

View File

@ -0,0 +1,5 @@
import { css } from "linaria"
export const Button = css`
color: red;
`

View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Button = void 0;
var _linaria = require("linaria");
const Button = _linaria.css`
color: red;
`;
exports.Button = Button;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2lucHV0L2luZGV4LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGNzcyB9IGZyb20gXCJsaW5hcmlhXCJcblxuZXhwb3J0IGNvbnN0IEJ1dHRvbiA9IGNzc2BcbiAgICBjb2xvcjogcmVkO1xuYCJdLCJuYW1lcyI6WyJCdXR0b24iLCJjc3MiXSwibWFwcGluZ3MiOiI7Ozs7O0FBQW9CLEdBQVMsQ0FBVCxRQUFTO0FBRXRCLEtBQUssQ0FBQ0EsTUFBTSxHQUFHQyxRQUFHLEtBQUM7O0FBRTFCO1FBRmFELE1BQU0sR0FBTkEsTUFBTSJ9

View File

@ -430,6 +430,7 @@ impl Scope {
}
fn fold_ident(folder: &mut impl ModulePass, i: Ident) -> Result<Expr, Ident> {
let orig_span = i.span;
let v = folder.scope().idents.get(&i.to_id()).cloned();
match v {
None => Err(i),
@ -444,7 +445,7 @@ impl Scope {
let (ident, span) = scope.imports.get(&src).as_ref().unwrap().as_ref().unwrap();
let obj = {
let ident = Ident::new(ident.clone(), *span);
let ident = Ident::new(ident.clone(), orig_span.with_ctxt(span.ctxt));
if lazy {
Expr::Call(CallExpr {