Skip to content

Commit

Permalink
Never enable JSX in a .ts file (#7031)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Oct 7, 2021
1 parent aafc318 commit d2d4f1c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
@@ -0,0 +1,10 @@
interface HeaderAction {}

let setCurrentAction = (arg: any) => {};
let getCurrentAction = () => {
return {};
};

const setAction = (fields: Partial<HeaderAction>) => {
setCurrentAction({ ...<HeaderAction>getCurrentAction(), ...fields });
};
@@ -0,0 +1,5 @@
{
"dependencies": {
"react": "*"
}
}
10 changes: 10 additions & 0 deletions packages/core/integration-tests/test/typescript.js
Expand Up @@ -193,5 +193,15 @@ describe('typescript', function() {
fromTsx: text,
});
});

it('should handle legacy cast in .ts file', async function() {
if (config != null) {
return;
}
await bundle(
path.join(__dirname, '/integration/typescript-legacy-cast/index.ts'),
{config},
);
});
}
});
22 changes: 13 additions & 9 deletions packages/transformers/js/src/JSTransformer.js
Expand Up @@ -14,8 +14,8 @@ import {validateSchema, remapSourceLocation} from '@parcel/utils';
import {isMatch} from 'micromatch';

const JSX_EXTENSIONS = {
'.jsx': true,
'.tsx': true,
jsx: true,
tsx: true,
};

const JSX_PRAGMA = {
Expand Down Expand Up @@ -222,12 +222,7 @@ export default (new Transformer({
}
}

isJSX = Boolean(
compilerOptions?.jsx ||
pragma ||
JSX_EXTENSIONS[path.extname(config.searchPath)],
);

isJSX = Boolean(compilerOptions?.jsx || pragma);
decorators = compilerOptions?.experimentalDecorators;
}

Expand Down Expand Up @@ -359,6 +354,15 @@ export default (new Transformer({

let supportsModuleWorkers =
asset.env.shouldScopeHoist && asset.env.supports('worker-module', true);
let isJSX = Boolean(config?.isJSX);
if (asset.isSource) {
if (asset.type === 'ts') {
isJSX = false;
} else if (!isJSX) {
isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
}
}

let {
dependencies,
code: compiledCode,
Expand All @@ -380,7 +384,7 @@ export default (new Transformer({
is_worker: asset.env.isWorker(),
env,
is_type_script: asset.type === 'ts' || asset.type === 'tsx',
is_jsx: Boolean(config?.isJSX),
is_jsx: isJSX,
jsx_pragma: config?.pragma,
jsx_pragma_frag: config?.pragmaFrag,
automatic_jsx_runtime: Boolean(config?.automaticJSXRuntime),
Expand Down

0 comments on commit d2d4f1c

Please sign in to comment.