Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags parsing is too aggressive #1214

Closed
layershifter opened this issue Feb 20, 2023 · 3 comments · Fixed by #1216
Closed

Tags parsing is too aggressive #1214

layershifter opened this issue Feb 20, 2023 · 3 comments · Fixed by #1216
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@layershifter
Copy link
Contributor

Environment

  • Linaria version: @linaria/[email protected]
  • 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

@layershifter layershifter added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Feb 20, 2023
@github-actions github-actions bot removed the needs: triage 🏷 Issue needs to be checked and prioritized label Feb 20, 2023
@Anber Anber closed this as completed in a3ad617 Feb 21, 2023
@therealgilles
Copy link

@Anber I think you fixed the cases you added test cases for but you did not fix this particular bug. This issue should be re-opened.

@therealgilles
Copy link

More specifically this case is still failing:

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

export type StyledReturn = ReturnType<typeof styled>;

@layershifter
Copy link
Contributor Author

@Anber I bumped reproduction to latest and indeed, it still reproes: https://stackblitz.com/edit/node-hyqpx9?file=package.json,testB.js

This happens because validateParams(params, ['tag', '...'], TaggedTemplateProcessor.SKIP); does not throw: isValidParams returns true as ... satisfies any constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants