Skip to content

Commit

Permalink
fix(babel, react, shaker): tag in runtime is not supported (fixes #1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Jul 26, 2022
1 parent c5ed76e commit 2abc55b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/three-emus-turn.md
@@ -0,0 +1,7 @@
---
'@linaria/babel-preset': patch
'@linaria/react': patch
'@linaria/shaker': patch
---

Fix 'Using the tag in runtime is not supported' in some enviroments (fixes #1021)
2 changes: 1 addition & 1 deletion packages/babel/src/index.ts
Expand Up @@ -30,7 +30,7 @@ export { default as peek } from './utils/peek';
export { default as processTemplateExpression } from './utils/processTemplateExpression';

function isEnabled(caller?: TransformCaller & { evaluate?: true }) {
return caller?.name !== 'linaria' || !caller.evaluate;
return caller?.name !== 'linaria' || caller.evaluate === true;
}

export default function linaria(babel: ConfigAPI, options: PluginOptions) {
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/index.ts
@@ -1,2 +1,4 @@
export { default as styled } from './styled';
export type { StyledJSXIntrinsics, Styled } from './styled';
export type { CSSProperties } from '@linaria/core';
export type { StyledMeta } from '@linaria/tags';
4 changes: 2 additions & 2 deletions packages/react/src/processors/styled.ts
Expand Up @@ -48,13 +48,13 @@ export default class StyledProcessor extends TaggedTemplateProcessor {
constructor(params: Params, ...args: TailProcessorParams) {
validateParams(
params,
['tag', ['call', 'member'], 'template'],
['tag', ['call', 'member'], ['template', 'call']],
'Invalid usage of `styled` tag'
);

const [tag, tagOp, template] = params;

super([tag, template], ...args);
super([tag, template[0] === 'call' ? ['template', []] : template], ...args);

let component: WrappedNode | undefined;
if (tagOp[0] === 'call' && tagOp.length === 2) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/styled.ts
Expand Up @@ -246,7 +246,7 @@ type ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = {}>(
? StyledMeta & TOrigCmp
: StyledComponent<OwnProps & TTrgProps>;

type StyledJSXIntrinsics = {
export type StyledJSXIntrinsics = {
readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;
};

Expand Down
3 changes: 3 additions & 0 deletions packages/shaker/src/index.ts
Expand Up @@ -19,6 +19,9 @@ const getShakerConfig = (only: string[] | null): TransformOptions => {

const config = {
ast: true,
caller: {
name: 'linaria',
},
envName: 'linaria',
targets: {
node: 'current',
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2abc55b

Please sign in to comment.