@linaria/utils
Advanced tools
Comparing version 4.3.3 to 4.3.4
@@ -10,4 +10,4 @@ /* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */ | ||
import isTypedNode from './isTypedNode'; | ||
export const sideEffectImport = item => item.imported === null; | ||
export const explicitImport = item => item.imported !== null; | ||
export const sideEffectImport = item => item.imported === 'side-effect'; | ||
export const explicitImport = item => item.imported !== 'side-effect'; | ||
function getValue({ | ||
@@ -62,3 +62,3 @@ node | ||
state.imports.push({ | ||
imported: null, | ||
imported: 'side-effect', | ||
local: path, | ||
@@ -206,7 +206,6 @@ source | ||
} | ||
function getImportExportTypeByInteropFunction(path) { | ||
function getCalleeName(path) { | ||
const callee = path.get('callee'); | ||
let name; | ||
if (callee.isIdentifier()) { | ||
name = callee.node.name; | ||
return callee.node.name; | ||
} | ||
@@ -216,5 +215,9 @@ if (callee.isMemberExpression()) { | ||
if (property.isIdentifier()) { | ||
name = property.node.name; | ||
return property.node.name; | ||
} | ||
} | ||
return undefined; | ||
} | ||
function getImportExportTypeByInteropFunction(path) { | ||
const name = getCalleeName(path); | ||
if (name === undefined) { | ||
@@ -372,3 +375,3 @@ return undefined; | ||
state.imports.push({ | ||
imported: null, | ||
imported: 'side-effect', | ||
local: container, | ||
@@ -566,3 +569,28 @@ source | ||
} | ||
if (parentPath?.isExportSpecifier()) { | ||
if (parentPath?.isCallExpression() && referencePath.listKey === 'arguments') { | ||
// The defined variable is used as a function argument. Let's try to figure out what is imported. | ||
const importType = getImportExportTypeByInteropFunction(parentPath); | ||
if (!importType) { | ||
// Imported value is used as an unknown function argument, | ||
// so we can't predict usage and import it as is. | ||
result.push(importItem); | ||
break; | ||
} | ||
if (importType === 'default') { | ||
result.push({ | ||
...importItem, | ||
imported: 'default', | ||
local: parentPath.get('id') | ||
}); | ||
continue; | ||
} | ||
if (importType === 'import:*') { | ||
result.push(importItem); | ||
break; | ||
} | ||
warn('evaluator:collectExportsAndImports:unfoldNamespaceImports', 'Unknown import type', importType); | ||
result.push(importItem); | ||
continue; | ||
} | ||
if (parentPath?.isExportSpecifier() || parentPath?.isExportDefaultDeclaration()) { | ||
// The whole namespace is re-exported | ||
@@ -569,0 +597,0 @@ result.push(importItem); |
@@ -18,5 +18,5 @@ "use strict"; | ||
const sideEffectImport = item => item.imported === null; | ||
const sideEffectImport = item => item.imported === 'side-effect'; | ||
exports.sideEffectImport = sideEffectImport; | ||
const explicitImport = item => item.imported !== null; | ||
const explicitImport = item => item.imported !== 'side-effect'; | ||
exports.explicitImport = explicitImport; | ||
@@ -72,3 +72,3 @@ function getValue({ | ||
state.imports.push({ | ||
imported: null, | ||
imported: 'side-effect', | ||
local: path, | ||
@@ -216,7 +216,6 @@ source | ||
} | ||
function getImportExportTypeByInteropFunction(path) { | ||
function getCalleeName(path) { | ||
const callee = path.get('callee'); | ||
let name; | ||
if (callee.isIdentifier()) { | ||
name = callee.node.name; | ||
return callee.node.name; | ||
} | ||
@@ -226,5 +225,9 @@ if (callee.isMemberExpression()) { | ||
if (property.isIdentifier()) { | ||
name = property.node.name; | ||
return property.node.name; | ||
} | ||
} | ||
return undefined; | ||
} | ||
function getImportExportTypeByInteropFunction(path) { | ||
const name = getCalleeName(path); | ||
if (name === undefined) { | ||
@@ -382,3 +385,3 @@ return undefined; | ||
state.imports.push({ | ||
imported: null, | ||
imported: 'side-effect', | ||
local: container, | ||
@@ -578,3 +581,28 @@ source | ||
} | ||
if (parentPath !== null && parentPath !== void 0 && parentPath.isExportSpecifier()) { | ||
if (parentPath !== null && parentPath !== void 0 && parentPath.isCallExpression() && referencePath.listKey === 'arguments') { | ||
// The defined variable is used as a function argument. Let's try to figure out what is imported. | ||
const importType = getImportExportTypeByInteropFunction(parentPath); | ||
if (!importType) { | ||
// Imported value is used as an unknown function argument, | ||
// so we can't predict usage and import it as is. | ||
result.push(importItem); | ||
break; | ||
} | ||
if (importType === 'default') { | ||
result.push({ | ||
...importItem, | ||
imported: 'default', | ||
local: parentPath.get('id') | ||
}); | ||
continue; | ||
} | ||
if (importType === 'import:*') { | ||
result.push(importItem); | ||
break; | ||
} | ||
(0, _logger.warn)('evaluator:collectExportsAndImports:unfoldNamespaceImports', 'Unknown import type', importType); | ||
result.push(importItem); | ||
continue; | ||
} | ||
if (parentPath !== null && parentPath !== void 0 && parentPath.isExportSpecifier() || parentPath !== null && parentPath !== void 0 && parentPath.isExportDefaultDeclaration()) { | ||
// The whole namespace is re-exported | ||
@@ -581,0 +609,0 @@ result.push(importItem); |
{ | ||
"name": "@linaria/utils", | ||
"version": "4.3.3", | ||
"version": "4.3.4", | ||
"description": "Blazing fast zero-runtime CSS in JS library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import type { NodePath } from '@babel/traverse'; | ||
import type { Identifier, MemberExpression } from '@babel/types'; | ||
export interface ISideEffectImport { | ||
imported: null; | ||
imported: 'side-effect'; | ||
local: NodePath; | ||
@@ -6,0 +6,0 @@ source: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
408986
4277