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

@linaria/shaker: export * is removed #808

Closed
Tracked by #18936
layershifter opened this issue Jul 22, 2021 · 1 comment
Closed
Tracked by #18936

@linaria/shaker: export * is removed #808

layershifter opened this issue Jul 22, 2021 · 1 comment
Assignees
Labels
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

Comments

@layershifter
Copy link
Contributor

layershifter commented Jul 22, 2021

Environment

  • Linaria version: @linaria/babel-preset@3.0.0-beta.7, @linaria/shaker@3.0.0-beta.8
  • Bundler (+ version): N/A
  • Node.js version: 12.19.0 (Windows/Ubuntu), 14.16.0 (Windows)
  • OS: Windows 10, Ubuntu 20.04 LTS on WSL

Description

Originally started there, #800 (comment).

Failing fixture contains named exports (foo, bar) and a re-export in index.js, there is an issue with resolving them (check using-shaker.js). For comparison I added evaluation with @babel/register (check using-babel.js).

I followed debugging guide and dumped output.

DEBUG=linaria* LINARIA_LOG=debug node using-shaker.js > log.txt 2>&1
log.txt
2021-07-22T17:29:55.568Z linaria:eval-cache:has  node-chgmv6\src\failing\index.js:foo 
/w2xANp8edpAaux540sDkccUqFY=
2021-07-22T17:29:55.568Z linaria:module:prepare-evaluation  
node-chgmv6\src\failing\index.js using shaker
2021-07-22T17:29:55.607Z linaria:evaluator:shaker:transform  Transform 
node-chgmv6\src\failing\index.js with options {
	  "configFile": false,
	  "babelrc": false,
	  "presets": [
	    [
	      "node-chgmv6\\node_modules\\@linaria\\preeval\\lib\\index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ],
	    [
	      "node-chgmv6\\node_modules\\@babel\\preset-env\\lib\\index.js",
	      {
	        "targets": "ie 11",
	        "include": [
	          "@babel/plugin-transform-template-literals"
	        ]
	      }
	    ],
	    [
	      "node-chgmv6\\node_modules\\@linaria\\babel-preset\\lib\\index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ]
	  ],
	  "plugins": [
	    [
	      "node-chgmv6\\node_modules\\@babel\\plugin-transform-runtime\\lib\\index.js",
	      {
	        "useESModules": false
	      }
	    ],
	    "node-chgmv6\\node_modules\\babel-plugin-transform-react-remove-prop-types\\lib\\i
ndex.js",
	    
"node-chgmv6\\node_modules\\@babel\\plugin-transform-modules-commonjs\\lib\\index.js",
	    "node-chgmv6\\node_modules\\@babel\\plugin-proposal-export-namespace-from\\lib\\in
dex.js",
	    "node-chgmv6\\node_modules\\@linaria\\babel-preset\\lib\\dynamic-import-noop.js"
	  ],
	  "caller": {
	    "name": "linaria",
	    "evaluate": true
	  },
	  "filename": "node-chgmv6\\src\\failing\\index.js",
	  "ast": true
	}
2021-07-22T17:29:59.106Z linaria:evaluator:shaker:shake  source (exports: foo):
	"use strict";
	
	var _foo = require("./foo");
	
	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	Object.keys(_foo).forEach(function (key) {
	  if (key === "default" || key === "__esModule") return;
	  if (key in exports && exports[key] === _foo[key]) return;
	  Object.defineProperty(exports, key, {
	    enumerable: true,
	    get: function get() {
	      return _foo[key];
	    }
	  });
	});
2021-07-22T17:29:59.111Z linaria:evaluator:shaker:shake  
	Program ❌
	|-directives
	| 0=Directive ❌
	| | |-value
	| | | |=DirectiveLiteral ❌
	|-body
	| 0=VariableDeclaration ❌
	| | |-declarations
	| | | 0=VariableDeclarator ❌
	| | | | |-id
	| | | | | |=Identifier _foo ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=CallExpression ❌
	| | | | | | |-callee
	| | | | | | | |=Identifier require ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-arguments
	| | | | | | | 0=StringLiteral ./foo ❌
	| | | | | | |-typeParameters
	| | | | | | |-typeArguments
	| 1=ExpressionStatement ❌
	| | |-expression
	| | | |=CallExpression ❌
	| | | | |-callee
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=Identifier Object ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier defineProperty ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-arguments
	| | | | | 0=Identifier exports ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | | 1=StringLiteral __esModule ❌
	| | | | | 2=ObjectExpression ❌
	| | | | | | |-properties
	| | | | | | | 0=ObjectProperty ❌
	| | | | | | | | |-key
	| | | | | | | | | |=Identifier value ❌
	| | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | |-decorators
	| | | | | | | | |-value
	| | | | | | | | | |=BooleanLiteral ❌
	| | | | | | | | |-decorators
	| | | | |-typeParameters
	| | | | |-typeArguments
	| 2=ExpressionStatement ❌
	| | |-expression
	| | | |=CallExpression ❌
	| | | | |-callee
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=CallExpression ❌
	| | | | | | | | |-callee
	| | | | | | | | | |=MemberExpression ❌
	| | | | | | | | | | |-object
	| | | | | | | | | | | |=Identifier Object ❌
	| | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | |-decorators
	| | | | | | | | | | |-property
	| | | | | | | | | | | |=Identifier keys ❌
	| | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | |-decorators
	| | | | | | | | |-arguments
	| | | | | | | | | 0=Identifier _foo ❌
	| | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | |-decorators
	| | | | | | | | |-typeParameters
	| | | | | | | | |-typeArguments
	| | | | | | |-property
	| | | | | | | |=Identifier forEach ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-arguments
	| | | | | 0=FunctionExpression ❌
	| | | | | | |-id
	| | | | | | |-params
	| | | | | | | 0=Identifier key ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-body
	| | | | | | | |=BlockStatement ❌
	| | | | | | | | |-directives
	| | | | | | | | |-body
	| | | | | | | | | 0=IfStatement ❌
	| | | | | | | | | | |-test
	| | | | | | | | | | | |=LogicalExpression ❌
	| | | | | | | | | | | | |-left
	| | | | | | | | | | | | | |=BinaryExpression === ❌
	| | | | | | | | | | | | | | |-left
	| | | | | | | | | | | | | | | |=Identifier key ❌
	| | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | |-right
	| | | | | | | | | | | | | | | |=StringLiteral default ❌
	| | | | | | | | | | | | |-right
	| | | | | | | | | | | | | |=BinaryExpression === ❌
	| | | | | | | | | | | | | | |-left
	| | | | | | | | | | | | | | | |=Identifier key ❌
	| | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | |-right
	| | | | | | | | | | | | | | | |=StringLiteral __esModule ❌
	| | | | | | | | | | |-consequent
	| | | | | | | | | | | |=ReturnStatement ❌
	| | | | | | | | | | | | |-argument
	| | | | | | | | | | |-alternate
	| | | | | | | | | 1=IfStatement ❌
	| | | | | | | | | | |-test
	| | | | | | | | | | | |=LogicalExpression ❌
	| | | | | | | | | | | | |-left
	| | | | | | | | | | | | | |=BinaryExpression in ❌
	| | | | | | | | | | | | | | |-left
	| | | | | | | | | | | | | | | |=Identifier key ❌
	| | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | |-right
	| | | | | | | | | | | | | | | |=Identifier exports ❌
	| | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | |-right
	| | | | | | | | | | | | | |=BinaryExpression === ❌
	| | | | | | | | | | | | | | |-left
	| | | | | | | | | | | | | | | |=MemberExpression ❌
	| | | | | | | | | | | | | | | | |-object
	| | | | | | | | | | | | | | | | | |=Identifier exports ❌
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | | |-property
	| | | | | | | | | | | | | | | | | |=Identifier key ❌
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | |-right
	| | | | | | | | | | | | | | | |=MemberExpression ❌
	| | | | | | | | | | | | | | | | |-object
	| | | | | | | | | | | | | | | | | |=Identifier _foo ❌
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | | |-property
	| | | | | | | | | | | | | | | | | |=Identifier key ❌
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | |-consequent
	| | | | | | | | | | | |=ReturnStatement ❌
	| | | | | | | | | | | | |-argument
	| | | | | | | | | | |-alternate
	| | | | | | | | | 2=ExpressionStatement ❌
	| | | | | | | | | | |-expression
	| | | | | | | | | | | |=CallExpression ❌
	| | | | | | | | | | | | |-callee
	| | | | | | | | | | | | | |=MemberExpression ❌
	| | | | | | | | | | | | | | |-object
	| | | | | | | | | | | | | | | |=Identifier Object ❌
	| | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | |-property
	| | | | | | | | | | | | | | | |=Identifier defineProperty ❌
	| | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | |-arguments
	| | | | | | | | | | | | | 0=Identifier exports ❌
	| | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | 1=Identifier key ❌
	| | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | 2=ObjectExpression ❌
	| | | | | | | | | | | | | | |-properties
	| | | | | | | | | | | | | | | 0=ObjectProperty ❌
	| | | | | | | | | | | | | | | | |-key
	| | | | | | | | | | | | | | | | | |=Identifier enumerable ❌
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | | |-value
	| | | | | | | | | | | | | | | | | |=BooleanLiteral ❌
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | 1=ObjectProperty ❌
	| | | | | | | | | | | | | | | | |-key
	| | | | | | | | | | | | | | | | | |=Identifier get ❌
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | | |-value
	| | | | | | | | | | | | | | | | | |=FunctionExpression ❌
	| | | | | | | | | | | | | | | | | | |-id
	| | | | | | | | | | | | | | | | | | | |=Identifier get ❌
	| | | | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | | | | |-params
	| | | | | | | | | | | | | | | | | | |-body
	| | | | | | | | | | | | | | | | | | | |=BlockStatement ❌
	| | | | | | | | | | | | | | | | | | | | |-directives
	| | | | | | | | | | | | | | | | | | | | |-body
	| | | | | | | | | | | | | | | | | | | | | 0=ReturnStatement ❌
	| | | | | | | | | | | | | | | | | | | | | | |-argument
	| | | | | | | | | | | | | | | | | | | | | | | |=MemberExpression ❌
	| | | | | | | | | | | | | | | | | | | | | | | | |-object
	| | | | | | | | | | | | | | | | | | | | | | | | | |=Identifier _foo ❌
	| | | | | | | | | | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | | | | | | | | | | |-property
	| | | | | | | | | | | | | | | | | | | | | | | | | |=Identifier key ❌
	| | | | | | | | | | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | | | | | | | |-returnType
	| | | | | | | | | | | | | | | | | | |-typeParameters
	| | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | | | |-typeParameters
	| | | | | | | | | | | | |-typeArguments
	| | | | | | |-returnType
	| | | | | | |-typeParameters
	| | | | |-typeParameters
	| | | | |-typeArguments
	
2021-07-22T17:29:59.111Z linaria:evaluator:shaker:generate  Generate shaken source code node-chgmv6\src\failing\index.js
2021-07-22T17:29:59.112Z linaria:module:evaluate  node-chgmv6\src\failing\index.js (only foo):
	
2021-07-22T17:29:59.113Z linaria:eval-cache:set  node-chgmv6\src\failing\index.js:foo /w2xANp8edpAaux540sDkccUqFY=

According to the output:

  • 🟥 shaker is evaluated for src/failing/index.js and export foo, fails to find foo and removes everything...
	"use strict";
	
	var _foo = require("./foo");
	
	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	Object.keys(_foo).forEach(function (key) {
	  if (key === "default" || key === "__esModule") return;
	  if (key in exports && exports[key] === _foo[key]) return;
	  Object.defineProperty(exports, key, {
	    enumerable: true,
	    get: function get() {
	      return _foo[key];
	    }
	  });
	});
2021-07-22T17:32:13.763Z linaria:evaluator:shaker:shake  source (exports: foo): --- ✂ STRIPPED ---
2021-07-22T17:32:13.766Z linaria:evaluator:shaker:shake  --- ✂ STRIPPED ---
2021-07-22T17:32:13.766Z linaria:evaluator:shaker:generate  Generate shaken source code node-chgmv6\src\failing\index.js
2021-07-22T17:32:13.767Z linaria:module:evaluate  node-chgmv6\src\failing\index.js (only foo):  --- 💣THIS IS EMPTY MODULE ---

Reproducible Demo

https://stackblitz.com/edit/node-chgmv6
you can either download project or execute code built-in terminal

$ node using-babel.js

fixtureName failing
exports['foo'] foo

$ node using-shaker.js

fixtureName failing
mod.exports['foo'] undefined # 🟥 this should be "foo"
@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 Jul 22, 2021
@github-actions github-actions bot added needs: triage 🏷 Issue needs to be checked and prioritized and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Jul 22, 2021
@Anber Anber self-assigned this Jul 23, 2021
@Anber
Copy link
Collaborator

Anber commented Jul 23, 2021

It was simpler than I expected :)

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 needs: triage 🏷 Issue needs to be checked and prioritized
Projects
None yet
Development

No branches or pull requests

2 participants