Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set swc option keepClassNames whenever possible #1344

Merged
merged 8 commits into from May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6,580 changes: 6,520 additions & 60 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -112,8 +112,8 @@
},
"devDependencies": {
"@microsoft/api-extractor": "^7.15.2",
"@swc/core": ">=1.2.45",
"@swc/wasm": ">=1.2.45",
"@swc/core": ">=1.2.50",
"@swc/wasm": ">=1.2.50",
"@types/chai": "^4.0.4",
"@types/diff": "^4.0.2",
"@types/lodash": "^4.14.151",
Expand Down Expand Up @@ -143,8 +143,8 @@
"util.promisify": "^1.0.1"
},
"peerDependencies": {
"@swc/core": ">=1.2.45",
"@swc/wasm": ">=1.2.45",
"@swc/core": ">=1.2.50",
"@swc/wasm": ">=1.2.50",
"@types/node": "*",
"typescript": ">=2.7"
},
Expand Down
4 changes: 2 additions & 2 deletions src/test/index.spec.ts
Expand Up @@ -345,15 +345,15 @@ test.suite('ts-node', (test) => {
`${cmdNoProject} --transpiler ts-node/transpilers/swc-experimental transpile-only-swc`
);
expect(err).to.equal(null);
expect(stdout).to.contain('hello world');
expect(stdout).to.contain('Hello World!');
});

test('should support third-party transpilers via tsconfig', async () => {
const { err, stdout } = await exec(
`${cmdNoProject} transpile-only-swc-via-tsconfig`
);
expect(err).to.equal(null);
expect(stdout).to.contain('hello world');
expect(stdout).to.contain('Hello World!');
});

test('should pipe into `ts-node` and evaluate', async () => {
Expand Down
9 changes: 6 additions & 3 deletions src/transpilers/swc.ts
Expand Up @@ -55,6 +55,8 @@ export function create(createOptions: SwcTranspilerOptions): Transpiler {
const nonTsxOptions = createSwcOptions(false);
const tsxOptions = createSwcOptions(true);
function createSwcOptions(isTsx: boolean): swcTypes.Options {
const swcTarget = targetMapping.get(target!) ?? 'es3';
const keepClassNames = target! >= /* ts.ScriptTarget.ES2016 */ 3;
return {
sourceMaps: sourceMap,
// isModule: true,
Expand All @@ -71,7 +73,7 @@ export function create(createOptions: SwcTranspilerOptions): Transpiler {
decorators: experimentalDecorators,
dynamicImport: true,
},
target: targetMapping.get(target!) ?? 'es3',
target: swcTarget,
transform: {
decoratorMetadata: emitDecoratorMetadata,
legacyDecorator: true,
Expand All @@ -81,9 +83,10 @@ export function create(createOptions: SwcTranspilerOptions): Transpiler {
useBuiltins: false,
pragma: jsxFactory!,
pragmaFrag: jsxFragmentFactory!,
},
} as swcTypes.ReactConfig,
},
},
keepClassNames,
} as swcTypes.JscConfig,
};
}

Expand Down
7 changes: 6 additions & 1 deletion tests/transpile-only-swc-via-tsconfig/index.ts
@@ -1,4 +1,9 @@
// Test for #1343
const Decorator = function () {};
@Decorator
class World {}

// intentional type errors to check transpile-only ESM loader skips type checking
parseInt(1101, 2);
const x: number = 'hello world';
const x: number = `Hello ${World.name}!`;
console.log(x);
4 changes: 3 additions & 1 deletion tests/transpile-only-swc-via-tsconfig/tsconfig.json
Expand Up @@ -4,8 +4,10 @@
"transpiler": "ts-node/transpilers/swc-experimental"
},
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"allowJs": true,
"jsx": "react"
"jsx": "react",
"experimentalDecorators": true
}
}
7 changes: 6 additions & 1 deletion tests/transpile-only-swc/index.ts
@@ -1,4 +1,9 @@
// Test for #1343
const Decorator = function () {};
@Decorator
class World {}

// intentional type errors to check transpile-only ESM loader skips type checking
parseInt(1101, 2);
const x: number = 'hello world';
const x: number = `Hello ${World.name}!`;
console.log(x);
4 changes: 3 additions & 1 deletion tests/transpile-only-swc/tsconfig.json
@@ -1,7 +1,9 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"allowJs": true,
"jsx": "react"
"jsx": "react",
"experimentalDecorators": true
}
}