Skip to content

Commit

Permalink
Update: prepare effectiveReactLib variable to set react pragma lib na…
Browse files Browse the repository at this point in the history
…me temporary
  • Loading branch information
Shinyaigeek committed Dec 16, 2021
1 parent 3aedb45 commit e05804a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
1 change: 0 additions & 1 deletion packages/core/integration-tests/test/transpilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ describe('transpilation', function () {
);

let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(file.includes('preact/jsx-runtime'));
assert(file.includes('_jsxRuntime.jsx("div"'));
});

Expand Down
46 changes: 7 additions & 39 deletions packages/transformers/js/src/JSTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,38 +126,6 @@ const SCRIPT_ERRORS = {
},
};

function convertAliasReactIntoPragma(
alias: string | {|[string]: string|},
): 'react' | 'preact' | 'hyperapp' | 'nervjs' {
if (typeof alias === 'string') {
switch (alias) {
case 'react': {
return 'react';
}
case 'preact/compat':
case 'preact-compat':
case 'preact': {
return 'preact';
}
case 'hyperapp': {
return 'hyperapp';
}
case 'nervjs': {
return 'nervjs';
}
default: {
return 'react';
}
}
} else {
for (const key in alias) {
return convertAliasReactIntoPragma(alias[key]);
}
}

return 'react';
}

type TSConfig = {
compilerOptions?: {
// https://www.typescriptlang.org/tsconfig#jsx
Expand Down Expand Up @@ -231,15 +199,15 @@ export default (new Transformer({
jsxImportSource = compilerOptions?.jsxImportSource;
automaticJSXRuntime = true;
} else if (reactLib) {
reactLib =
pkg?.alias && pkg.alias['react']
? convertAliasReactIntoPragma(pkg.alias['react'])
let effectiveReactLib =
pkg?.alias && pkg.alias['react'] === 'preact/compat'
? 'preact'
: reactLib;
let automaticVersion = JSX_PRAGMA[reactLib]?.automatic;
let automaticVersion = JSX_PRAGMA[effectiveReactLib]?.automatic;
let reactLibVersion =
pkg?.dependencies?.[reactLib] ||
pkg?.devDependencies?.[reactLib] ||
pkg?.peerDependencies?.[reactLib];
pkg?.dependencies?.[effectiveReactLib] ||
pkg?.devDependencies?.[effectiveReactLib] ||
pkg?.peerDependencies?.[effectiveReactLib];
let minReactLibVersion =
reactLibVersion != null && reactLibVersion !== '*'
? semver.minVersion(reactLibVersion)?.toString()
Expand Down

0 comments on commit e05804a

Please sign in to comment.