linaria
linaria copied to clipboard
Build failed for js literal template
Environment
- Linaria version: 4.1.2
- Bundler (+ version): [email protected]
- Node.js version: v14.17.6
- OS: Mac OS (M1 chip)
Description
There are two files, index.js and literal.js, bellow is their contents
index.js
import { css } from '@linaria/core'
import { literal } from './literal'
export const style = css`
width: 1px;
`
literal.js
export const literal = `${window.location.name}`
When build, will get error
Unexpected token (1:26)
> 1 | export const literal = `${}`;
Reproducible Demo
https://github.com/anc95/linaria-template-string-demo
I have investigated the issue and found the causing source is here https://github.com/callstack/linaria/blob/1c697031a983799422dd4be2dee6dc0956250392/packages/babel/src/plugins/preeval.ts#L157-L165
In prepare eval phase, linaria will remove the related nodes of global var (in my example is window.name), so we will get code
export const literal = `${}`;
then in the next evaluator phase, linaria use babel to transform the source code generated by #phase1, got syntax error.