mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
fix(es/config): Respect .swcrc
(#4735)
This commit is contained in:
parent
286e654c95
commit
9966e98ac6
@ -986,17 +986,6 @@ impl Config {
|
||||
///
|
||||
/// - typescript: `tsx` will be modified if file extension is `ts`.
|
||||
pub fn adjust(&mut self, file: &Path) {
|
||||
if self.jsc.syntax.is_none() || matches!(self.jsc.syntax, Some(Syntax::Es(..))) {
|
||||
if file.extension() == Some("ts".as_ref()) {
|
||||
self.jsc.syntax = Some(Syntax::Typescript(TsConfig::default()));
|
||||
} else if file.extension() == Some("tsx".as_ref()) {
|
||||
self.jsc.syntax = Some(Syntax::Typescript(TsConfig {
|
||||
tsx: true,
|
||||
..Default::default()
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(Syntax::Typescript(TsConfig { tsx, dts, .. })) = &mut self.jsc.syntax {
|
||||
let is_dts = file
|
||||
.file_name()
|
||||
|
@ -1,4 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _config = require("../config");
|
||||
|
@ -1 +1 @@
|
||||
export { };
|
||||
import { module } from "../config";
|
||||
|
@ -1,2 +1,4 @@
|
||||
import something from "../module_with_default_export.js"; /* This!? */
|
||||
import { something_else } from "http://bonzo.com/mod"; // There?
|
||||
/* Hello! */ export * from "./stuff.js";
|
||||
/* Maybe like this? */ let _var; // Or so?
|
||||
|
@ -1,9 +1,10 @@
|
||||
import * as swcHelpers from "@swc/helpers";
|
||||
export class Foo {
|
||||
nested() {
|
||||
let Foo1 = class Foo {
|
||||
};
|
||||
Foo1.foo = "foo";
|
||||
Foo1.bar = Foo1.foo;
|
||||
swcHelpers.defineProperty(Foo1, "foo", "foo");
|
||||
swcHelpers.defineProperty(Foo1, "bar", Foo1.foo);
|
||||
return new Foo1();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
it("should auto-detect tsx", async () => {
|
||||
it("should allow using tsx", async () => {
|
||||
const filename = join(
|
||||
__dirname,
|
||||
"..",
|
||||
@ -21,6 +21,7 @@ it("should auto-detect tsx", async () => {
|
||||
target: "es5",
|
||||
parser: {
|
||||
syntax: "typescript",
|
||||
tsx: true
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -35,7 +36,7 @@ export default function foo() {
|
||||
`);
|
||||
});
|
||||
|
||||
it("should auto-detect tsx even with no parser option", async () => {
|
||||
it("should respect .swcrc without parser option", async () => {
|
||||
const filename = join(
|
||||
__dirname,
|
||||
"..",
|
||||
|
38
node-swc/__tests__/transform/issue_4734_test.mjs
Normal file
38
node-swc/__tests__/transform/issue_4734_test.mjs
Normal file
@ -0,0 +1,38 @@
|
||||
import swc from "../../..";
|
||||
import { dirname, join } from "path";
|
||||
import { platform } from "os";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
it("should transpile decorators", async () => {
|
||||
const filename = join(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"tests",
|
||||
"issue-4734",
|
||||
"1",
|
||||
"index.ts"
|
||||
);
|
||||
console.log(filename);
|
||||
const { code } = await swc.transformFile(filename, {});
|
||||
expect(code).toMatchInlineSnapshot(`
|
||||
"var __decorate = this && this.__decorate || function(decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === \\"object\\" && typeof Reflect.decorate === \\"function\\") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
class TestClass {
|
||||
abc() {}
|
||||
}
|
||||
__decorate([
|
||||
foo
|
||||
], TestClass.prototype, \\"abc\\", null);
|
||||
function foo(target, propertyKey) {
|
||||
console.log(\`Decorating \${target}.\${String(propertyKey)}\`);
|
||||
}
|
||||
"
|
||||
`);
|
||||
});
|
@ -1,6 +1,10 @@
|
||||
{
|
||||
"jsc": {
|
||||
"target": "es2017",
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": true
|
||||
},
|
||||
"transform": {
|
||||
"react": {
|
||||
"runtime": "automatic"
|
||||
|
12
node-swc/tests/issue-4734/1/.swcrc
Normal file
12
node-swc/tests/issue-4734/1/.swcrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true
|
||||
},
|
||||
"target": "es2020"
|
||||
}
|
||||
}
|
8
node-swc/tests/issue-4734/1/index.ts
Normal file
8
node-swc/tests/issue-4734/1/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
class TestClass {
|
||||
@foo
|
||||
abc() { }
|
||||
}
|
||||
|
||||
function foo(target: unknown, propertyKey: string | symbol) {
|
||||
console.log(`Decorating ${target}.${String(propertyKey)}`)
|
||||
}
|
Loading…
Reference in New Issue
Block a user