Skip to content

Commit

Permalink
Fix compilation errors when building CRA project (issue #745) (#748)
Browse files Browse the repository at this point in the history
* fix(babel): better dehydration of jsx-components

* fix(cli): rename cli binary back to "linaria"

* fix(babel): replace babel helpers esm imports with cjs (#745)
  • Loading branch information
Anber committed Apr 11, 2021
1 parent 03631ce commit 75f5d8d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Component = props => tag;"
exports[`replaces functional component 1`] = `
"import React from 'react';
const Component = props => {
const Component = () => {
return <></>;
};"
`;
8 changes: 7 additions & 1 deletion packages/babel/src/evaluators/visitors/JSXElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ export default function JSXElement(path: NodePath<JSXElementNode>) {
);
}

body.replaceWith(emptyBody);
const node: typeof scopePath.node = {
...scopePath.node,
body: emptyBody,
params: [],
};

scopePath.replaceWith(node);
} else {
path.replaceWith(emptyFragment);
}
Expand Down
16 changes: 14 additions & 2 deletions packages/babel/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ const createCustomDebug = (depth: number) => (
debug(`${modulePrefix}:${namespaces}`, arg1, ...args);
};

const cookModuleId = (rawId: string) => {
// It's a dirty hack for avoiding conflicts with babel-preset-react-app
// https://github.com/callstack/linaria/issues/745
// FIXME @Anber: I'll try to figure out a better solution. Probably, using Terser as a shaker's core can solve problems with interfered plugins.
return rawId.replace(
'/@babel/runtime/helpers/esm/',
'/@babel/runtime/helpers/'
);
};

class Module {
static invalidate: () => void;
static invalidateEvalCache: () => void;
Expand Down Expand Up @@ -134,7 +144,8 @@ class Module {
this.debug('prepare', filename);
}

resolve = (id: string) => {
resolve = (rawId: string) => {
const id = cookModuleId(rawId);
const extensions = ((NativeModule as unknown) as {
_extensions: { [key: string]: Function };
})._extensions;
Expand Down Expand Up @@ -167,7 +178,8 @@ class Module {
ensure: () => void;
cache: typeof cache;
} = Object.assign(
(id: string) => {
(rawId: string) => {
const id = cookModuleId(rawId);
this.debug('require', id);
if (id in builtins) {
// The module is in the allowed list of builtin node modules
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"access": "public"
},
"description": "Blazing fast zero-runtime CSS in JS library",
"main": "lib/cli.js",
"module": "esm/cli.js",
"main": "lib/linaria.js",
"module": "esm/linaria.js",
"bin": {
"linaria": "bin/linaria.js"
},
Expand Down
File renamed without changes.
18 changes: 4 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4285,20 +4285,10 @@ camelcase@^6.0.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.0.0.tgz#5259f7c30e35e278f1bdc2a4d91230b37cad981e"
integrity sha512-8KMDF1Vz2gzOq54ONPJS65IvTUaB1cHJ2DMM7MbPmLZljDH1qpzzLsWdiN9pHh6qvkRVDTi/07+eNGch/oLU4w==

caniuse-lite@^1.0.30001109:
version "1.0.30001151"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001151.tgz#1ddfde5e6fff02aad7940b4edb7d3ac76b0cb00b"
integrity sha512-Zh3sHqskX6mHNrqUerh+fkf0N72cMxrmflzje/JyVImfpknscMnkeJrlFGJcqTmaa0iszdYptGpWMJCRQDkBVw==

caniuse-lite@^1.0.30001111:
version "1.0.30001112"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001112.tgz#0fffc3b934ff56ff0548c37bc9dad7d882bcf672"
integrity sha512-J05RTQlqsatidif/38aN3PGULCLrg8OYQOlJUKbeYVzC2mGZkZLIztwRlB3MtrfLmawUmjFlNJvy/uhwniIe1Q==

caniuse-lite@^1.0.30001157:
version "1.0.30001159"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001159.tgz#bebde28f893fa9594dadcaa7d6b8e2aa0299df20"
integrity sha512-w9Ph56jOsS8RL20K9cLND3u/+5WASWdhC/PPrf+V3/HsM3uHOavWOR1Xzakbv4Puo/srmPHudkmCRWM7Aq+/UA==
caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001111, caniuse-lite@^1.0.30001157:
version "1.0.30001208"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001208.tgz"
integrity sha512-OE5UE4+nBOro8Dyvv0lfx+SRtfVIOM9uhKqFmJeUbGriqhhStgp1A0OyBpgy3OUF8AhYCT+PVwPC1gMl2ZcQMA==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 75f5d8d

Please sign in to comment.