mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
fix(common): Fix logic for excluding FileName
from source maps (#7900)
**Description:** This PR also modifies React transform to use `FileName::Internal` and makes `SourceMapGenConfig` skips `FileName::Internal`. **Related issue:** - Closes #5272
This commit is contained in:
parent
e5f7a9dab0
commit
aa6495519b
@ -681,10 +681,10 @@ impl SourceMapGenConfig for SwcSourceMapConfig<'_> {
|
||||
}
|
||||
|
||||
fn skip(&self, f: &FileName) -> bool {
|
||||
if let FileName::Custom(s) = f {
|
||||
s.starts_with('<')
|
||||
} else {
|
||||
false
|
||||
match f {
|
||||
FileName::Internal(..) => true,
|
||||
FileName::Custom(s) => s.starts_with('<'),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
crates/swc/tests/fixture/issues-5xxx/5272/1/input/.swcrc
Normal file
20
crates/swc/tests/fixture/issues-5xxx/5272/1/input/.swcrc
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"sourceMaps": true,
|
||||
"module": {
|
||||
"type": "commonjs",
|
||||
"strict": false,
|
||||
"strictMode": false
|
||||
},
|
||||
"jsc": {
|
||||
"target": "es5",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"dynamicImport": true
|
||||
},
|
||||
"transform": {
|
||||
"hidden": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import { Foo } from "./a";
|
||||
|
||||
describe("a", () => {
|
||||
it("does its thing", () => {
|
||||
const a = new Foo();
|
||||
expect(a.bar()).toBe(3);
|
||||
expect(a.foo()).toBe(2);
|
||||
});
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
import { Base } from "../b/base";
|
||||
export class Foo extends Base {
|
||||
bar() {
|
||||
return 1 + this.foo();
|
||||
}
|
||||
}
|
16
crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
Normal file
16
crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAN;;gBAAMA;iCAAAA;aAAAA;kCAAAA;;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
|
||||
"names": [
|
||||
"Foo",
|
||||
"bar",
|
||||
"foo",
|
||||
"Base"
|
||||
],
|
||||
"sources": [
|
||||
"../../input/source/a/a.ts"
|
||||
],
|
||||
"sourcesContent": [
|
||||
"import { Base } from \"../b/base\";\nexport class Foo extends Base {\n bar() {\n return 1 + this.foo();\n }\n}"
|
||||
],
|
||||
"version": 3
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
{
|
||||
"mappings": ";;;iBAAoB;AAEpBA,SAAS,KAAK;IACVC,GAAG,kBAAkB;QACjB,IAAMC,IAAI,IAAIC,MAAG;QACjBC,OAAOF,EAAEG,GAAG,IAAIC,IAAI,CAAC;QACrBF,OAAOF,EAAEK,GAAG,IAAID,IAAI,CAAC;IACzB;AACJ",
|
||||
"names": [
|
||||
"describe",
|
||||
"it",
|
||||
"a",
|
||||
"Foo",
|
||||
"expect",
|
||||
"bar",
|
||||
"toBe",
|
||||
"foo"
|
||||
],
|
||||
"sources": [
|
||||
"../../input/source/a/a.spec.ts"
|
||||
],
|
||||
"sourcesContent": [
|
||||
"import { Foo } from \"./a\";\n\ndescribe(\"a\", () => {\n it(\"does its thing\", () => {\n const a = new Foo();\n expect(a.bar()).toBe(3);\n expect(a.foo()).toBe(2);\n });\n});"
|
||||
],
|
||||
"version": 3
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _a = require("./a");
|
||||
describe("a", function() {
|
||||
it("does its thing", function() {
|
||||
var a = new _a.Foo();
|
||||
expect(a.bar()).toBe(3);
|
||||
expect(a.foo()).toBe(2);
|
||||
});
|
||||
});
|
@ -0,0 +1,32 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "Foo", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return Foo;
|
||||
}
|
||||
});
|
||||
var _class_call_check = require("@swc/helpers/_/_class_call_check");
|
||||
var _create_class = require("@swc/helpers/_/_create_class");
|
||||
var _inherits = require("@swc/helpers/_/_inherits");
|
||||
var _create_super = require("@swc/helpers/_/_create_super");
|
||||
var _base = require("../b/base");
|
||||
var Foo = /*#__PURE__*/ function(Base) {
|
||||
"use strict";
|
||||
_inherits._(Foo, Base);
|
||||
var _super = _create_super._(Foo);
|
||||
function Foo() {
|
||||
_class_call_check._(this, Foo);
|
||||
return _super.apply(this, arguments);
|
||||
}
|
||||
_create_class._(Foo, [
|
||||
{
|
||||
key: "bar",
|
||||
value: function bar() {
|
||||
return 1 + this.foo();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return Foo;
|
||||
}(_base.Base);
|
@ -1266,6 +1266,9 @@ impl SourceMap {
|
||||
Some(ref f) if f.start_pos <= pos && pos < f.end_pos => f,
|
||||
_ => {
|
||||
f = self.lookup_source_file(pos);
|
||||
if config.skip(&f.name) {
|
||||
continue;
|
||||
}
|
||||
src_id = builder.add_source(&config.file_name_to_source(&f.name));
|
||||
|
||||
inline_sources_content = config.inline_sources_content(&f.name);
|
||||
@ -1447,8 +1450,9 @@ pub trait SourceMapGenConfig {
|
||||
true
|
||||
}
|
||||
|
||||
fn skip(&self, _f: &FileName) -> bool {
|
||||
false
|
||||
/// By default, we skip internal files.
|
||||
fn skip(&self, f: &FileName) -> bool {
|
||||
matches!(f, FileName::Internal(..))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,10 @@ impl Config {
|
||||
.into_iter()
|
||||
.map(|(k, v)| {
|
||||
let parse = |s| {
|
||||
let fm = cm
|
||||
.new_source_file(FileName::Custom(format!("<umd-config-{}.js>", s)), s);
|
||||
let fm = cm.new_source_file(
|
||||
FileName::Internal(format!("<umd-config-{}.js>", s)),
|
||||
s,
|
||||
);
|
||||
|
||||
parse_file_as_expr(
|
||||
&fm,
|
||||
|
@ -46,7 +46,10 @@ pub fn const_modules(
|
||||
fn parse_option(cm: &SourceMap, name: &str, src: String) -> Arc<Expr> {
|
||||
static CACHE: Lazy<DashMap<String, Arc<Expr>, ARandomState>> = Lazy::new(DashMap::default);
|
||||
|
||||
let fm = cm.new_source_file(FileName::Custom(format!("<const-module-{}.js>", name)), src);
|
||||
let fm = cm.new_source_file(
|
||||
FileName::Internal(format!("<const-module-{}.js>", name)),
|
||||
src,
|
||||
);
|
||||
if let Some(expr) = CACHE.get(&**fm.src) {
|
||||
return expr.clone();
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ pub fn parse_expr_for_jsx(
|
||||
src: String,
|
||||
top_level_mark: Mark,
|
||||
) -> Arc<Box<Expr>> {
|
||||
let fm = cm.new_source_file(FileName::Custom(format!("<jsx-config-{}.js>", name)), src);
|
||||
let fm = cm.new_source_file(FileName::Internal(format!("<jsx-config-{}.js>", name)), src);
|
||||
|
||||
parse_file_as_expr(
|
||||
&fm,
|
||||
|
Loading…
Reference in New Issue
Block a user