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: named exports are removed #800

Closed
Tracked by #18936
layershifter opened this issue Jul 15, 2021 · 8 comments
Closed
Tracked by #18936

@linaria/shaker: named exports are removed #800

layershifter opened this issue Jul 15, 2021 · 8 comments
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

Comments

@layershifter
Copy link
Contributor

Environment

  • Linaria version: @linaria/babel-preset@3.0.0-beta.7, @linaria/shaker@3.0.0-beta.7
  • 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

Hello folks!

I am using @linaria/babel-preset & @linaria/shaker for our CSS-in-JS and it looks that we spot an issue, please check "Reproducible Demo" section first.

Failing fixture contains named exports (foo, bar) and 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-15T10:26:42.900Z linaria:module:prepare  node-yfjhdp/src/failing/index.js
2021-07-15T10:26:42.901Z linaria:eval-cache:has  node-yfjhdp/src/failing/index.js:foo uuxblAIIBNTE0Zy5qpMYn06kV2Q=
2021-07-15T10:26:42.902Z linaria:module:prepare-evaluation  node-yfjhdp/src/failing/index.js using shaker
2021-07-15T10:26:43.014Z linaria:evaluator:shaker:transform  Transform node-yfjhdp/src/failing/index.js with options {
	  "configFile": false,
	  "babelrc": false,
	  "presets": [
	    [
	      "node-yfjhdp/node_modules/@linaria/preeval/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@babel/preset-env/lib/index.js",
	      {
	        "targets": "ie 11",
	        "include": [
	          "@babel/plugin-transform-template-literals"
	        ]
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@linaria/babel-preset/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ]
	  ],
	  "plugins": [
	    [
	      "node-yfjhdp/node_modules/@babel/plugin-transform-runtime/lib/index.js",
	      {
	        "useESModules": false
	      }
	    ],
	    "node-yfjhdp/node_modules/babel-plugin-transform-react-remove-prop-types/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-proposal-export-namespace-from/lib/index.js",
	    "node-yfjhdp/node_modules/@linaria/babel-preset/lib/dynamic-import-noop.js"
	  ],
	  "caller": {
	    "name": "linaria",
	    "evaluate": true
	  },
	  "filename": "node-yfjhdp/src/failing/index.js",
	  "ast": true
	}
2021-07-15T10:26:46.932Z linaria:evaluator:shaker:shake  source (exports: foo):
	"use strict";

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	Object.defineProperty(exports, "foo", {
	  enumerable: true,
	  get: function get() {
	    return _foo.foo;
	  }
	});
	Object.defineProperty(exports, "bar", {
	  enumerable: true,
	  get: function get() {
	    return _foo.bar;
	  }
	});

	var _foo = require("./foo");
2021-07-15T10:26:46.936Z linaria:evaluator:shaker:shake
	Program ✅
	|-directives
	| 0=Directive ✅
	| | |-value
	| | | |=DirectiveLiteral ✅
	|-body
	| 0=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
	| 1=ExpressionStatement ✅
	| | |-expression
	| | | |=CallExpression ✅
	| | | | |-callee
	| | | | | |=MemberExpression ✅
	| | | | | | |-object
	| | | | | | | |=Identifier Object ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier defineProperty ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-arguments
	| | | | | 0=Identifier exports ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | | 1=StringLiteral foo ✅
	| | | | | 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 foo ✅
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | |-returnType
	| | | | | | | | | | |-typeParameters
	| | | | | | | | |-decorators
	| | | | |-typeParameters
	| | | | |-typeArguments
	| 2=ExpressionStatement ❌
	| | |-expression
	| | | |=CallExpression ❌
	| | | | |-callee
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=Identifier Object ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier defineProperty ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-arguments
	| | | | | 0=Identifier exports ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | | 1=StringLiteral bar ❌
	| | | | | 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 bar ❌
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | |-returnType
	| | | | | | | | | | |-typeParameters
	| | | | | | | | |-decorators
	| | | | |-typeParameters
	| | | | |-typeArguments
	| 3=VariableDeclaration ✅
	| | |-declarations
	| | | 0=VariableDeclarator ✅
	| | | | |-id
	| | | | | |=Identifier _foo ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=CallExpression ✅
	| | | | | | |-callee
	| | | | | | | |=Identifier require ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-arguments
	| | | | | | | 0=StringLiteral ./foo ✅
	| | | | | | |-typeParameters
	| | | | | | |-typeArguments

2021-07-15T10:26:46.937Z linaria:evaluator:shaker:generate  Generate shaken source code node-yfjhdp/src/failing/index.js
2021-07-15T10:26:46.938Z linaria:module:evaluate  node-yfjhdp/src/failing/index.js (only foo):
	"use strict";

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	Object.defineProperty(exports, "foo", {
	  enumerable: true,
	  get: function get() {
	    return _foo.foo;
	  }
	});

	var _foo = require("./foo");
2021-07-15T10:26:46.940Z linaria:module:require  ./foo
2021-07-15T10:26:46.952Z linaria:module:cached:not-exist  ./foo
2021-07-15T10:26:46.952Z linaria:sub-module-1:prepare  node-yfjhdp/src/failing/foo.js
2021-07-15T10:26:46.955Z linaria:eval-cache:has  node-yfjhdp/src/failing/foo.js:default mMjPY4CR4zXfVZiT3jGpJSXDb7Y=
2021-07-15T10:26:46.955Z linaria:sub-module-1:prepare-evaluation  node-yfjhdp/src/failing/foo.js using shaker
2021-07-15T10:26:46.956Z linaria:evaluator:shaker:transform  Transform node-yfjhdp/src/failing/foo.js with options {
	  "configFile": false,
	  "babelrc": false,
	  "presets": [
	    [
	      "node-yfjhdp/node_modules/@linaria/preeval/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@babel/preset-env/lib/index.js",
	      {
	        "targets": "ie 11",
	        "include": [
	          "@babel/plugin-transform-template-literals"
	        ]
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@linaria/babel-preset/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ]
	  ],
	  "plugins": [
	    [
	      "node-yfjhdp/node_modules/@babel/plugin-transform-runtime/lib/index.js",
	      {
	        "useESModules": false
	      }
	    ],
	    "node-yfjhdp/node_modules/babel-plugin-transform-react-remove-prop-types/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-proposal-export-namespace-from/lib/index.js",
	    "node-yfjhdp/node_modules/@linaria/babel-preset/lib/dynamic-import-noop.js"
	  ],
	  "caller": {
	    "name": "linaria",
	    "evaluate": true
	  },
	  "filename": "node-yfjhdp/src/failing/foo.js",
	  "ast": true
	}
2021-07-15T10:26:46.984Z linaria:evaluator:shaker:shake  source (exports: default):
	"use strict";

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	exports.bar = exports.foo = void 0;
	var foo = 'foo';
	exports.foo = foo;
	var bar = 'bar';
	exports.bar = bar;
2021-07-15T10:26:46.985Z linaria:evaluator:shaker:shake
	Program ❌
	|-directives
	| 0=Directive ❌
	| | |-value
	| | | |=DirectiveLiteral ❌
	|-body
	| 0=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
	| 1=ExpressionStatement ❌
	| | |-expression
	| | | |=AssignmentExpression ❌
	| | | | |-left
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=Identifier exports ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier bar ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-right
	| | | | | |=AssignmentExpression ❌
	| | | | | | |-left
	| | | | | | | |=MemberExpression ❌
	| | | | | | | | |-object
	| | | | | | | | | |=Identifier exports ❌
	| | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | |-decorators
	| | | | | | | | |-property
	| | | | | | | | | |=Identifier foo ❌
	| | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | |-decorators
	| | | | | | |-right
	| | | | | | | |=UnaryExpression ❌
	| | | | | | | | |-argument
	| | | | | | | | | |=NumericLiteral 0 ❌
	| 2=VariableDeclaration ❌
	| | |-declarations
	| | | 0=VariableDeclarator ❌
	| | | | |-id
	| | | | | |=Identifier foo ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=StringLiteral foo ❌
	| 3=ExpressionStatement ❌
	| | |-expression
	| | | |=AssignmentExpression ❌
	| | | | |-left
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=Identifier exports ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier foo ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-right
	| | | | | |=Identifier foo ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| 4=VariableDeclaration ❌
	| | |-declarations
	| | | 0=VariableDeclarator ❌
	| | | | |-id
	| | | | | |=Identifier bar ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=StringLiteral bar ❌
	| 5=ExpressionStatement ❌
	| | |-expression
	| | | |=AssignmentExpression ❌
	| | | | |-left
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=Identifier exports ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier bar ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-right
	| | | | | |=Identifier bar ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators

2021-07-15T10:26:46.986Z linaria:evaluator:shaker:generate  Generate shaken source code node-yfjhdp/src/failing/foo.js
2021-07-15T10:26:46.987Z linaria:sub-module-1:evaluate  node-yfjhdp/src/failing/foo.js (only default):

2021-07-15T10:26:46.988Z linaria:eval-cache:set  node-yfjhdp/src/failing/foo.js:default mMjPY4CR4zXfVZiT3jGpJSXDb7Y=
2021-07-15T10:26:46.988Z linaria:eval-cache:set  node-yfjhdp/src/failing/index.js:foo uuxblAIIBNTE0Zy5qpMYn06kV2Q=
fixtureName failing
mod.exports['foo'] undefined

2021-07-15T10:26:46.994Z linaria:module:prepare  node-yfjhdp/src/passing/index.js
2021-07-15T10:26:46.994Z linaria:eval-cache:has  node-yfjhdp/src/passing/index.js:foo ipSaOhTbHA+fkDJ+pZMwrFUPNxs=
2021-07-15T10:26:46.994Z linaria:module:prepare-evaluation  node-yfjhdp/src/passing/index.js using shaker
2021-07-15T10:26:46.995Z linaria:evaluator:shaker:transform  Transform node-yfjhdp/src/passing/index.js with options {
	  "configFile": false,
	  "babelrc": false,
	  "presets": [
	    [
	      "node-yfjhdp/node_modules/@linaria/preeval/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@babel/preset-env/lib/index.js",
	      {
	        "targets": "ie 11",
	        "include": [
	          "@babel/plugin-transform-template-literals"
	        ]
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@linaria/babel-preset/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ]
	  ],
	  "plugins": [
	    [
	      "node-yfjhdp/node_modules/@babel/plugin-transform-runtime/lib/index.js",
	      {
	        "useESModules": false
	      }
	    ],
	    "node-yfjhdp/node_modules/babel-plugin-transform-react-remove-prop-types/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-proposal-export-namespace-from/lib/index.js",
	    "node-yfjhdp/node_modules/@linaria/babel-preset/lib/dynamic-import-noop.js"
	  ],
	  "caller": {
	    "name": "linaria",
	    "evaluate": true
	  },
	  "filename": "node-yfjhdp/src/passing/index.js",
	  "ast": true
	}
2021-07-15T10:26:47.065Z linaria:evaluator:shaker:shake  source (exports: foo):
	"use strict";

	var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	Object.defineProperty(exports, "foo", {
	  enumerable: true,
	  get: function get() {
	    return _foo.default;
	  }
	});

	var _foo = _interopRequireDefault(require("./foo"));
2021-07-15T10:26:47.067Z linaria:evaluator:shaker:shake
	Program ✅
	|-directives
	| 0=Directive ✅
	| | |-value
	| | | |=DirectiveLiteral ✅
	|-body
	| 0=VariableDeclaration ✅
	| | |-declarations
	| | | 0=VariableDeclarator ✅
	| | | | |-id
	| | | | | |=Identifier _interopRequireDefault ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=CallExpression ✅
	| | | | | | |-callee
	| | | | | | | |=Identifier require ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-arguments
	| | | | | | | 0=StringLiteral @babel/runtime/helpers/interopRequireDefault ✅
	| | | | | | |-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
	| | | | | | | |=Identifier Object ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier defineProperty ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-arguments
	| | | | | 0=Identifier exports ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | | 1=StringLiteral foo ✅
	| | | | | 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 default ✅
	| | | | | | | | | | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | | | | | | | | | |-decorators
	| | | | | | | | | | |-returnType
	| | | | | | | | | | |-typeParameters
	| | | | | | | | |-decorators
	| | | | |-typeParameters
	| | | | |-typeArguments
	| 3=VariableDeclaration ✅
	| | |-declarations
	| | | 0=VariableDeclarator ✅
	| | | | |-id
	| | | | | |=Identifier _foo ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=CallExpression ✅
	| | | | | | |-callee
	| | | | | | | |=Identifier _interopRequireDefault ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-arguments
	| | | | | | | 0=CallExpression ✅
	| | | | | | | | |-callee
	| | | | | | | | | |=Identifier require ✅
	| | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | |-decorators
	| | | | | | | | |-arguments
	| | | | | | | | | 0=StringLiteral ./foo ✅
	| | | | | | | | |-typeParameters
	| | | | | | | | |-typeArguments
	| | | | | | |-typeParameters
	| | | | | | |-typeArguments

2021-07-15T10:26:47.067Z linaria:evaluator:shaker:generate  Generate shaken source code node-yfjhdp/src/passing/index.js
2021-07-15T10:26:47.068Z linaria:module:evaluate  node-yfjhdp/src/passing/index.js (only foo):
	"use strict";

	var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	Object.defineProperty(exports, "foo", {
	  enumerable: true,
	  get: function get() {
	    return _foo.default;
	  }
	});

	var _foo = _interopRequireDefault(require("./foo"));
2021-07-15T10:26:47.069Z linaria:module:require  @babel/runtime/helpers/interopRequireDefault
2021-07-15T10:26:47.074Z linaria:module:cached:not-exist  @babel/runtime/helpers/interopRequireDefault
2021-07-15T10:26:47.075Z linaria:sub-module-1:prepare  node-yfjhdp/node_modules/@babel/runtime/helpers/interopRequireDefault.js
2021-07-15T10:26:47.080Z linaria:eval-cache:has  node-yfjhdp/node_modules/@babel/runtime/helpers/interopRequireDefault.js:default bBu+h5XK9KnZ6etfFJpBoMvBpdc=
2021-07-15T10:26:47.080Z linaria:sub-module-1:ignore  node-yfjhdp/node_modules/@babel/runtime/helpers/interopRequireDefault.js
2021-07-15T10:26:47.081Z linaria:eval-cache:set  node-yfjhdp/node_modules/@babel/runtime/helpers/interopRequireDefault.js:default bBu+h5XK9KnZ6etfFJpBoMvBpdc=
2021-07-15T10:26:47.081Z linaria:module:require  ./foo
2021-07-15T10:26:47.088Z linaria:module:cached:not-exist  ./foo
2021-07-15T10:26:47.088Z linaria:sub-module-1:prepare  node-yfjhdp/src/passing/foo.js
2021-07-15T10:26:47.091Z linaria:eval-cache:has  node-yfjhdp/src/passing/foo.js:default 821Zv7iiUGLTjDPu5mSGUvzguB0=
2021-07-15T10:26:47.091Z linaria:sub-module-1:prepare-evaluation  node-yfjhdp/src/passing/foo.js using shaker
2021-07-15T10:26:47.091Z linaria:evaluator:shaker:transform  Transform node-yfjhdp/src/passing/foo.js with options {
	  "configFile": false,
	  "babelrc": false,
	  "presets": [
	    [
	      "node-yfjhdp/node_modules/@linaria/preeval/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@babel/preset-env/lib/index.js",
	      {
	        "targets": "ie 11",
	        "include": [
	          "@babel/plugin-transform-template-literals"
	        ]
	      }
	    ],
	    [
	      "node-yfjhdp/node_modules/@linaria/babel-preset/lib/index.js",
	      {
	        "displayName": false,
	        "evaluate": true,
	        "rules": [
	          {},
	          {
	            "test": {},
	            "action": "ignore"
	          }
	        ],
	        "babelOptions": {
	          "configFile": false,
	          "babelrc": false
	        }
	      }
	    ]
	  ],
	  "plugins": [
	    [
	      "node-yfjhdp/node_modules/@babel/plugin-transform-runtime/lib/index.js",
	      {
	        "useESModules": false
	      }
	    ],
	    "node-yfjhdp/node_modules/babel-plugin-transform-react-remove-prop-types/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js",
	    "node-yfjhdp/node_modules/@babel/plugin-proposal-export-namespace-from/lib/index.js",
	    "node-yfjhdp/node_modules/@linaria/babel-preset/lib/dynamic-import-noop.js"
	  ],
	  "caller": {
	    "name": "linaria",
	    "evaluate": true
	  },
	  "filename": "node-yfjhdp/src/passing/foo.js",
	  "ast": true
	}
2021-07-15T10:26:47.105Z linaria:evaluator:shaker:shake  source (exports: default):
	"use strict";

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	exports.default = exports.bar = void 0;
	var foo = 'foo';
	var bar = 'bar';
	exports.bar = bar;
	var _default = foo;
	exports.default = _default;
2021-07-15T10:26:47.106Z linaria:evaluator:shaker:shake
	Program ✅
	|-directives
	| 0=Directive ✅
	| | |-value
	| | | |=DirectiveLiteral ✅
	|-body
	| 0=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
	| 1=ExpressionStatement ❌
	| | |-expression
	| | | |=AssignmentExpression ❌
	| | | | |-left
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=Identifier exports ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier default ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-right
	| | | | | |=AssignmentExpression ❌
	| | | | | | |-left
	| | | | | | | |=MemberExpression ❌
	| | | | | | | | |-object
	| | | | | | | | | |=Identifier exports ❌
	| | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | |-decorators
	| | | | | | | | |-property
	| | | | | | | | | |=Identifier bar ❌
	| | | | | | | | | | |-typeAnnotation
	| | | | | | | | | | |-decorators
	| | | | | | |-right
	| | | | | | | |=UnaryExpression ❌
	| | | | | | | | |-argument
	| | | | | | | | | |=NumericLiteral 0 ❌
	| 2=VariableDeclaration ✅
	| | |-declarations
	| | | 0=VariableDeclarator ✅
	| | | | |-id
	| | | | | |=Identifier foo ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=StringLiteral foo ✅
	| 3=VariableDeclaration ❌
	| | |-declarations
	| | | 0=VariableDeclarator ❌
	| | | | |-id
	| | | | | |=Identifier bar ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=StringLiteral bar ❌
	| 4=ExpressionStatement ❌
	| | |-expression
	| | | |=AssignmentExpression ❌
	| | | | |-left
	| | | | | |=MemberExpression ❌
	| | | | | | |-object
	| | | | | | | |=Identifier exports ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier bar ❌
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-right
	| | | | | |=Identifier bar ❌
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| 5=VariableDeclaration ✅
	| | |-declarations
	| | | 0=VariableDeclarator ✅
	| | | | |-id
	| | | | | |=Identifier _default ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| | | | |-init
	| | | | | |=Identifier foo ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators
	| 6=ExpressionStatement ✅
	| | |-expression
	| | | |=AssignmentExpression ✅
	| | | | |-left
	| | | | | |=MemberExpression ✅
	| | | | | | |-object
	| | | | | | | |=Identifier exports ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | | | |-property
	| | | | | | | |=Identifier default ✅
	| | | | | | | | |-typeAnnotation
	| | | | | | | | |-decorators
	| | | | |-right
	| | | | | |=Identifier _default ✅
	| | | | | | |-typeAnnotation
	| | | | | | |-decorators

2021-07-15T10:26:47.107Z linaria:evaluator:shaker:generate  Generate shaken source code node-yfjhdp/src/passing/foo.js
2021-07-15T10:26:47.108Z linaria:sub-module-1:evaluate  node-yfjhdp/src/passing/foo.js (only default):
	"use strict";

	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	var foo = 'foo';
	var _default = foo;
	exports.default = _default;
2021-07-15T10:26:47.109Z linaria:eval-cache:set  node-yfjhdp/src/passing/foo.js:default 821Zv7iiUGLTjDPu5mSGUvzguB0=
2021-07-15T10:26:47.109Z linaria:eval-cache:set  node-yfjhdp/src/passing/index.js:foo ipSaOhTbHA+fkDJ+pZMwrFUPNxs=
fixtureName passing
mod.exports['foo'] foo

According to the output:

  • shaker is evaluated for src/failing/index.js and removes unused code properly
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "foo", {
  enumerable: true,
  get: function get() {
    return _foo.foo;
  }
});

var _foo = require("./foo");
  • ✅ tries to require src/failing/foo.js
  • 🟥 shaker is called with exports: default, this results in removing all code from src/failing/foo.js
linaria:evaluator:shaker:shake  source (exports: default):
	"use strict";
	
	Object.defineProperty(exports, "__esModule", {
	  value: true
	});
	exports.bar = exports.foo = void 0;
	var foo = 'foo';
	exports.foo = foo;
	var bar = 'bar';
	exports.bar = bar;
linaria:evaluator:shaker:shake  --- ✂ STRIPPED ---	
linaria:evaluator:shaker:generate  Generate shaken source code node-yfjhdp/src/failing/foo.js
linaria:sub-module-1:evaluate  node-yfjhdp/src/failing/foo.js (only default): --- 💣THIS IS EMPTY MODULE ---

Reproducible Demo

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

$ node using-babel.js

fixtureName failing
exports['foo'] foo

fixtureName passing
exports['foo'] foo

$ node using-shaker.js

fixtureName failing
mod.exports['foo'] undefined # 🟥 this should be "foo"

fixtureName passing
mod.exports['foo'] 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 15, 2021
@github-actions github-actions bot removed the needs: triage 🏷 Issue needs to be checked and prioritized label Jul 15, 2021
@layershifter
Copy link
Contributor Author

As I see, technically it should be handled in MemberExpression:

MemberExpression(this: GraphBuilderState, node: MemberExpression) {
this.baseVisit(node);
if (t.isIdentifier(node.object) && t.isIdentifier(node.property)) {
// It's simple `foo.bar` expression. Is it a usage of a required library?
const declaration = this.scope.getDeclaration(node.object);
if (declaration && this.graph.importAliases.has(declaration)) {
// It is. We can remember what exactly we use from it.
const source = this.graph.importAliases.get(declaration)!;
this.graph.imports.get(source)!.push(node.property);
}
}
},

If I naively do:

      if (declaration && this.graph.importAliases.has(declaration)) {
        // It is. We can remember what exactly we use from it.
        const source = this.graph.importAliases.get(declaration)!;
        this.graph.imports.get(source)!.push(node.property);
-     }
+     } else {
+       this.graph.imports.set('./foo', [node.property]);
+     }

It's passing:

fixtureName failing
mod.exports['foo'] foo

The problem is that MemberExpression is executed before CallExpression (it creates entries in this.graph.imports)... Any suggestions, ideas?

@Anber
Copy link
Collaborator

Anber commented Jul 18, 2021

Thank you @layershifter for such a great issue!

PS Migration to @babel/traverse is raised from "it would be cool" to "ASAP" :)

@Anber
Copy link
Collaborator

Anber commented Jul 18, 2021

[I hope] fixed in 3.0.0-beta.8

@weyheyhey
Copy link

[I hope] fixed in 3.0.0-beta.8

If you replace export with export * from './foo'; the problem still remains: https://stackblitz.com/edit/node-z631tb

@layershifter
Copy link
Contributor Author

layershifter commented Jul 22, 2021

[I hope] fixed in 3.0.0-beta.8

The original issue is solved, but as @weyheyhey mention export * breaks 😥 @Anber should I create a separate issue for this?


Babel transforms it too:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _foo = require("./foo");

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];
    }
  });
});

@Anber
Copy link
Collaborator

Anber commented Jul 22, 2021

Damn, that code looks absolutely unshakable…
Probably, Shaker can detect that "reexport everything" pattern and then redirect to the original file, but that will not work if there are more than one export *.

Anyway, a new issue would be cool.

@Anber
Copy link
Collaborator

Anber commented Jul 22, 2021

In case of multiple export * we can try to return the requested value from every imported file:

var _foo = require("./foo");
var _bar = require("./bar");

exports.__linariaPreval = [_foo.value ?? _bar.value];

@layershifter
Copy link
Contributor Author

Damn, that code looks absolutely unshakable…
Probably, Shaker can detect that "reexport everything" pattern and then redirect to the original file, but that will not work if there are more than one export *.

Anyway, a new issue would be cool.

@Anber @weyheyhey I created #808 to track it. Honestly, don't have a good idea how to handle it.

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

No branches or pull requests

3 participants