@voltiso/transform
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -63,2 +63,12 @@ "use strict"; | ||
} | ||
function collectNodesOfKind(node, kind) { | ||
let nodesOfKind = []; | ||
if (node.kind === kind) | ||
nodesOfKind.push(node); | ||
node.forEachChild(child => { | ||
const moreNodesOfKind = collectNodesOfKind(child, kind); | ||
nodesOfKind = [...nodesOfKind, ...moreNodesOfKind]; | ||
}); | ||
return nodesOfKind; | ||
} | ||
// function getJSDocTags(type: ts.Type): readonly ts.JSDocTag[] { | ||
@@ -182,18 +192,32 @@ // const symbol = type.symbol as ts.Symbol | undefined | ||
} | ||
const newSymbolNames = collectSymbolNames(newNode); | ||
const symbolsOutOfScope = collectSymbolNames(newNode); | ||
// console.log(newSymbolNames) | ||
const symbolNames = collectSymbolNames(node); | ||
for (const symbolName of symbolNames) | ||
newSymbolNames.delete(symbolName); | ||
symbolsOutOfScope.delete(symbolName); | ||
// console.log('remaining symbols', newSymbolNames) | ||
for (const symbol of newSymbolNames) { | ||
for (const symbol of symbolsOutOfScope) { | ||
if (typeSymbols.has(symbol)) | ||
newSymbolNames.delete(symbol); | ||
symbolsOutOfScope.delete(symbol); | ||
} | ||
const canBeInlined = newSymbolNames.size === 0; | ||
if (!canBeInlined && options?.warn) { | ||
const message = `\n[@voltiso/transform] unable to inline ${getNodeText(node) || (0, transform_lib_1.stringFromSyntaxKind)(node.kind)} - symbols out of scope: ${[...newSymbolNames].join(', ')} \n @ ${getNodePositionStr(node)}`; | ||
const hasSymbolsOutOfScope = symbolsOutOfScope.size > 0; | ||
if (hasSymbolsOutOfScope && options?.warn) { | ||
const message = `\n[@voltiso/transform] unable to inline ${getNodeText(node) || (0, transform_lib_1.stringFromSyntaxKind)(node.kind)} - symbols out of scope: ${[...symbolsOutOfScope].join(', ')} \n @ ${getNodePositionStr(node)}`; | ||
// eslint-disable-next-line no-console | ||
console.warn(chalk_1.default.bgRed(message)); | ||
} | ||
const importTypeNodes = collectNodesOfKind(newNode, ts.SyntaxKind.ImportType); | ||
let containsImportAbsolutePath = false; | ||
for (const importTypeNode of importTypeNodes) { | ||
const child = getFirstChildOrSelf(getFirstChildOrSelf(importTypeNode)); | ||
if (ts.isStringLiteral(child) && child.text.startsWith('/')) { | ||
containsImportAbsolutePath = true; | ||
if (options?.warn) { | ||
const message = `\n[@voltiso/transform] unable to inline ${getNodeText(node) || (0, transform_lib_1.stringFromSyntaxKind)(node.kind)} - resulting node text would include absolute disk path import of '${child.text}' \n @ ${getNodePositionStr(node)}`; | ||
// eslint-disable-next-line no-console | ||
console.warn(chalk_1.default.bgRed(message)); | ||
} | ||
} | ||
} | ||
const canBeInlined = !hasSymbolsOutOfScope && !containsImportAbsolutePath; | ||
return canBeInlined; | ||
@@ -200,0 +224,0 @@ } |
@@ -34,2 +34,12 @@ // ⠀ⓥ 2022 🌩 🌩 ⠀ ⠀ | ||
} | ||
function collectNodesOfKind(node, kind) { | ||
let nodesOfKind = []; | ||
if (node.kind === kind) | ||
nodesOfKind.push(node); | ||
node.forEachChild(child => { | ||
const moreNodesOfKind = collectNodesOfKind(child, kind); | ||
nodesOfKind = [...nodesOfKind, ...moreNodesOfKind]; | ||
}); | ||
return nodesOfKind; | ||
} | ||
// function getJSDocTags(type: ts.Type): readonly ts.JSDocTag[] { | ||
@@ -153,18 +163,32 @@ // const symbol = type.symbol as ts.Symbol | undefined | ||
} | ||
const newSymbolNames = collectSymbolNames(newNode); | ||
const symbolsOutOfScope = collectSymbolNames(newNode); | ||
// console.log(newSymbolNames) | ||
const symbolNames = collectSymbolNames(node); | ||
for (const symbolName of symbolNames) | ||
newSymbolNames.delete(symbolName); | ||
symbolsOutOfScope.delete(symbolName); | ||
// console.log('remaining symbols', newSymbolNames) | ||
for (const symbol of newSymbolNames) { | ||
for (const symbol of symbolsOutOfScope) { | ||
if (typeSymbols.has(symbol)) | ||
newSymbolNames.delete(symbol); | ||
symbolsOutOfScope.delete(symbol); | ||
} | ||
const canBeInlined = newSymbolNames.size === 0; | ||
if (!canBeInlined && options?.warn) { | ||
const message = `\n[@voltiso/transform] unable to inline ${getNodeText(node) || stringFromSyntaxKind(node.kind)} - symbols out of scope: ${[...newSymbolNames].join(', ')} \n @ ${getNodePositionStr(node)}`; | ||
const hasSymbolsOutOfScope = symbolsOutOfScope.size > 0; | ||
if (hasSymbolsOutOfScope && options?.warn) { | ||
const message = `\n[@voltiso/transform] unable to inline ${getNodeText(node) || stringFromSyntaxKind(node.kind)} - symbols out of scope: ${[...symbolsOutOfScope].join(', ')} \n @ ${getNodePositionStr(node)}`; | ||
// eslint-disable-next-line no-console | ||
console.warn(chalk.bgRed(message)); | ||
} | ||
const importTypeNodes = collectNodesOfKind(newNode, ts.SyntaxKind.ImportType); | ||
let containsImportAbsolutePath = false; | ||
for (const importTypeNode of importTypeNodes) { | ||
const child = getFirstChildOrSelf(getFirstChildOrSelf(importTypeNode)); | ||
if (ts.isStringLiteral(child) && child.text.startsWith('/')) { | ||
containsImportAbsolutePath = true; | ||
if (options?.warn) { | ||
const message = `\n[@voltiso/transform] unable to inline ${getNodeText(node) || stringFromSyntaxKind(node.kind)} - resulting node text would include absolute disk path import of '${child.text}' \n @ ${getNodePositionStr(node)}`; | ||
// eslint-disable-next-line no-console | ||
console.warn(chalk.bgRed(message)); | ||
} | ||
} | ||
} | ||
const canBeInlined = !hasSymbolsOutOfScope && !containsImportAbsolutePath; | ||
return canBeInlined; | ||
@@ -171,0 +195,0 @@ } |
{ | ||
"name": "@voltiso/transform", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/voltiso/mono.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
50980
632