ts-transformer-keys
Advanced tools
Comparing version 0.4.0 to 0.4.1
{ | ||
"name": "ts-transformer-keys", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A TypeScript custom transformer which enables to obtain keys of given type.", | ||
@@ -29,5 +29,5 @@ "scripts": { | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.7.1", | ||
"mocha": "^6.2.0", | ||
"typescript": "^3.6.4" | ||
"@types/node": "^12.12.12", | ||
"mocha": "^6.2.2", | ||
"typescript": "^3.7.2" | ||
}, | ||
@@ -34,0 +34,0 @@ "peerDependencies": { |
@@ -71,2 +71,3 @@ # ts-transformer-keys | ||
// rollup.config.js | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import typescript from 'rollup-plugin-typescript2'; | ||
@@ -78,2 +79,3 @@ import keysTransformer from 'ts-transformer-keys/transformer'; | ||
plugins: [ | ||
resolve(), | ||
typescript({ transformers: [service => ({ | ||
@@ -85,3 +87,2 @@ before: [ keysTransformer(service.getProgram()) ], | ||
}; | ||
``` | ||
@@ -88,0 +89,0 @@ |
@@ -14,2 +14,5 @@ "use strict"; | ||
var typeChecker = program.getTypeChecker(); | ||
if (isKeysImportExpression(node)) { | ||
return; | ||
} | ||
if (!isKeysCallExpression(node, typeChecker)) { | ||
@@ -25,2 +28,17 @@ return node; | ||
} | ||
var indexJs = path.join(__dirname, 'index.js'); | ||
function isKeysImportExpression(node) { | ||
if (!ts.isImportDeclaration(node)) { | ||
return false; | ||
} | ||
var module = node.moduleSpecifier.text; | ||
try { | ||
return indexJs === (module.startsWith('.') | ||
? require.resolve(path.resolve(path.dirname(node.getSourceFile().fileName), module)) | ||
: require.resolve(module)); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} | ||
var indexTs = path.join(__dirname, 'index.d.ts'); | ||
@@ -27,0 +45,0 @@ function isKeysCallExpression(node, typeChecker) { |
@@ -9,9 +9,14 @@ import * as ts from 'typescript'; | ||
function visitNodeAndChildren(node: ts.SourceFile, program: ts.Program, context: ts.TransformationContext): ts.SourceFile; | ||
function visitNodeAndChildren(node: ts.Node, program: ts.Program, context: ts.TransformationContext): ts.Node; | ||
function visitNodeAndChildren(node: ts.Node, program: ts.Program, context: ts.TransformationContext): ts.Node { | ||
function visitNodeAndChildren(node: ts.Node, program: ts.Program, context: ts.TransformationContext): ts.Node | undefined; | ||
function visitNodeAndChildren(node: ts.Node, program: ts.Program, context: ts.TransformationContext): ts.Node | undefined { | ||
return ts.visitEachChild(visitNode(node, program), childNode => visitNodeAndChildren(childNode, program, context), context); | ||
} | ||
function visitNode(node: ts.Node, program: ts.Program): ts.Node { | ||
function visitNode(node: ts.SourceFile, program: ts.Program): ts.SourceFile; | ||
function visitNode(node: ts.Node, program: ts.Program): ts.Node | undefined; | ||
function visitNode(node: ts.Node, program: ts.Program): ts.Node | undefined { | ||
const typeChecker = program.getTypeChecker(); | ||
if (isKeysImportExpression(node)) { | ||
return; | ||
} | ||
if (!isKeysCallExpression(node, typeChecker)) { | ||
@@ -28,2 +33,19 @@ return node; | ||
const indexJs = path.join(__dirname, 'index.js'); | ||
function isKeysImportExpression(node: ts.Node): node is ts.ImportDeclaration { | ||
if (!ts.isImportDeclaration(node)) { | ||
return false; | ||
} | ||
const module = (node.moduleSpecifier as ts.StringLiteral).text; | ||
try { | ||
return indexJs === ( | ||
module.startsWith('.') | ||
? require.resolve(path.resolve(path.dirname(node.getSourceFile().fileName), module)) | ||
: require.resolve(module) | ||
); | ||
} catch(e) { | ||
return false; | ||
} | ||
} | ||
const indexTs = path.join(__dirname, 'index.d.ts'); | ||
@@ -30,0 +52,0 @@ function isKeysCallExpression(node: ts.Node, typeChecker: ts.TypeChecker): node is ts.CallExpression { |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
10796
117
162
2