Skip to content

Tags parsing is too aggressive #1214

@layershifter

Description

@layershifter

Environment

  • Linaria version: @linaria/babel-preset@4.4.2
  • Bundler (+ version): N/A
  • Node.js version: 16
  • OS: N/A

Description

There are cases when a tag parser (or traversal) is too aggressive and causes unexpected failures. There are two cases that I currently found.

CJS re-export produced by TS

// TS code
export { styled } from '@linaria/react'

⬇️⬇️⬇️

// CJS code
var react_1 = /*#__PURE__*/ require('@linaria/react');

Object.defineProperty(exports, 'styled', {
  enumerable: true,
  get: function () {
    return react_1.styled;
  },
});

Results in:

SyntaxError: /home/projects/node-hyqpx9/code/exampleB.js: /home/projects/node-hyqpx9/code/exampleB.js: Invalid usage of `styled` tag
  4 |   enumerable: true,
  5 |   get: function () {
> 6 |     return react_1.styled;
    |            ^^^^^^^
  7 |   },
  8 | });
  9 |
  • Source in ./code/exampleB.js
  • To run node ./testB.js

Usage of identifier in TS types

import { styled } from '@linaria/react';

export type StyledReturn = ReturnType<typeof styled>;

Results in:

SyntaxError: /home/projects/node-hyqpx9/code/exampleA.ts: /home/projects/node-hyqpx9/code/exampleA.ts: Invalid usage of `styled` tag
  1 | import { styled } from '@linaria/react';
  2 |
> 3 | export type StyledReturn = ReturnType<typeof styled>;
    |     
  • Source in ./code/exampleA.ts
  • To run node ./testA.js

Reproducible Demo

https://stackblitz.com/edit/node-hyqpx9

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug report 🦗Issue is probably a bug, but it needs to be checkedneeds: complete repro 🖥️Issue need to have complete repro provided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions