Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
fix: change swc's jsc.parser.syntax with a reasonable value
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan committed Apr 24, 2023
1 parent 2475217 commit d69a2bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/libuild-plugin-swc/src/es5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const es5Plugin = (filename?: string | ((filename: string) => string)): L
swcrc: false,
configFile: false,
extensions: {},
jsc: { target: 'es5' },
jsc: { target: 'es5', parser: { syntax: 'ecmascript' } },
isModule: 'unknown',
});
const result = await swcCompiler.transformSync(name, chunk.contents.toString());
Expand Down
17 changes: 12 additions & 5 deletions packages/libuild-plugin-swc/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const swcTransformPlugin = (
compiler.hooks.transform.tapPromise(pluginName, async (source): Promise<Source> => {
const { originalFilePath } = resolvePathAndQuery(source.path);
const { emitDecoratorMetadata = false, externalHelpers = false, pluginImport = [] } = options;
const isTs = source.loader === 'tsx' || source.loader === 'ts' || /\.tsx?$/i.test(originalFilePath);
const enableTsx = source.loader === 'tsx' || source.loader === 'jsx' || /\.tsx$|\.jsx$/i.test(originalFilePath);

// format is umd, disable swc-transform
Expand All @@ -40,11 +41,17 @@ export const swcTransformPlugin = (
swcrc: false,
configFile: false,
jsc: {
parser: {
syntax: 'typescript',
tsx: enableTsx,
decorators: true,
},
parser: isTs
? {
syntax: 'typescript',
tsx: enableTsx,
decorators: true,
}
: {
syntax: 'ecmascript',
jsx: enableTsx,
decorators: true,
},
transform: {
react: {
runtime: jsx === 'transform' ? 'classic' : 'automatic',
Expand Down
2 changes: 1 addition & 1 deletion packages/libuild-plugin-swc/src/umd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const umdPlugin = (filename?: string | ((filename: string) => string)): L
configFile: false,
extensions: {},
// transform by user-target
jsc: { target: getSwcTarget(compiler.config.target) },
jsc: { target: getSwcTarget(compiler.config.target), parser: { syntax: 'ecmascript' } },
module: {
type: 'umd',
},
Expand Down

0 comments on commit d69a2bf

Please sign in to comment.