Comparing version 3.2.1 to 3.2.2
Change Log | ||
========== | ||
### 3.2.2 | ||
- publicPath option was not working correctly for complex relative imports | ||
### 3.2.1 | ||
@@ -4,0 +7,0 @@ - support `useResolve` taking a dependency array |
{ | ||
"name": "jpex", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"description": "Javascript Prototype Extension", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/jpex.js", |
@@ -5,3 +5,3 @@ const { types: t } = require('@babel/core'); | ||
const alias = (programPath, path, jpex, filename) => { | ||
const alias = (programPath, path, { identifier, filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
@@ -12,3 +12,3 @@ const args = path.node.arguments; | ||
t.isMemberExpression(callee) && | ||
jpex.includes(callee.object.name) && | ||
identifier.includes(callee.object.name) && | ||
callee.property.name === 'alias' | ||
@@ -26,3 +26,3 @@ ); | ||
const type = getPath([ 'node', 'typeParameters', 'params', '0' ], path); | ||
const name = getConcreteTypeName(type, filename, programPath); | ||
const name = getConcreteTypeName(type, filename, publicPath, programPath); | ||
if (name != null) { | ||
@@ -29,0 +29,0 @@ args.unshift(t.stringLiteral(name)); |
@@ -14,3 +14,4 @@ const { types: t } = require('@babel/core'); | ||
if (!cache[key]) { | ||
cache[key] = key; | ||
const value = `${state.publicPath || state.filename}/${state.typeName}`; | ||
cache[key] = value; | ||
} | ||
@@ -26,3 +27,4 @@ const id = cache[key]; | ||
if (!cache[key]) { | ||
cache[key] = key; | ||
const value = `${state.publicPath || state.filename}/${state.typeName}`; | ||
cache[key] = value; | ||
} | ||
@@ -42,3 +44,4 @@ const id = cache[key]; | ||
if (!cache[key]) { | ||
cache[key] = key; | ||
const value = state.publicPath ? `${state.publicPath}/${path.node.imported.name}` : key; | ||
cache[key] = value; | ||
} | ||
@@ -50,3 +53,3 @@ const id = cache[key]; | ||
const getConcreteTypeName = (typeNode, filename, programPath) => { | ||
const getConcreteTypeName = (typeNode, filename, publicPath, programPath) => { | ||
if (t.isTSTypeReference(typeNode)) { | ||
@@ -59,2 +62,3 @@ const name = getPath([ 'typeName', 'name' ], typeNode); | ||
filename, | ||
publicPath, | ||
programPath, | ||
@@ -77,3 +81,3 @@ typeName: name, | ||
TSTypeAnnotation(path, state) { | ||
const name = getConcreteTypeName(path.node.typeAnnotation, state.filename, state.programPath); | ||
const name = getConcreteTypeName(path.node.typeAnnotation, state.filename, state.publicPath, state.programPath); | ||
state.key = name == null ? 'unknown' : name; | ||
@@ -83,3 +87,3 @@ }, | ||
const getFunctionParams = (path, deps, filename, programPath) => { | ||
const getFunctionParams = (path, deps, filename, publicPath, programPath) => { | ||
path.get('params').forEach((path) => { | ||
@@ -90,2 +94,3 @@ const ctx = { | ||
programPath, | ||
publicPath, | ||
}; | ||
@@ -99,5 +104,5 @@ path.traverse(tsTypeAnnotationVisitor, ctx); | ||
ClassMethod(path, state) { | ||
const { deps, filename, programPath } = state; | ||
const { deps, filename, programPath, publicPath } = state; | ||
if (path.node.key.name === 'constructor') { | ||
getFunctionParams(path, deps, filename, programPath); | ||
getFunctionParams(path, deps, filename, publicPath, programPath); | ||
} | ||
@@ -115,20 +120,20 @@ }, | ||
ArrowFunctionExpression(path, state) { | ||
const { deps, name, filename, programPath } = state; | ||
const { deps, name, filename, programPath, publicPath } = state; | ||
const { parent } = path; | ||
if (parent && parent.id && parent.id.name === name) { | ||
getFunctionParams(path, deps, filename, programPath); | ||
getFunctionParams(path, deps, filename, publicPath, programPath); | ||
} | ||
}, | ||
FunctionDeclaration(path, state) { | ||
const { deps, name, filename, programPath } = state; | ||
const { deps, name, filename, programPath, publicPath } = state; | ||
const { node } = path; | ||
if (node && node.id && node.id.name === name) { | ||
getFunctionParams(path, deps, filename, programPath); | ||
getFunctionParams(path, deps, filename, publicPath, programPath); | ||
} | ||
}, | ||
FunctionExpression(path, state) { | ||
const { deps, name, filename, programPath } = state; | ||
const { deps, name, filename, programPath, publicPath } = state; | ||
const { parent } = path; | ||
if (parent && parent.id && parent.id.name === name) { | ||
getFunctionParams(path, deps, filename, programPath); | ||
getFunctionParams(path, deps, filename, publicPath, programPath); | ||
} | ||
@@ -138,3 +143,3 @@ }, | ||
const extractFunctionParameterTypes = (programPath, arg, filename) => { | ||
const extractFunctionParameterTypes = (programPath, arg, filename, publicPath) => { | ||
const deps = []; | ||
@@ -145,2 +150,3 @@ const ctx = { | ||
filename, | ||
publicPath, | ||
}; | ||
@@ -152,5 +158,5 @@ if (t.isIdentifier(arg)) { | ||
} else if (t.isArrowFunctionExpression(arg)) { | ||
getFunctionParams(arg, deps, filename, programPath); | ||
getFunctionParams(arg, deps, filename, publicPath, programPath); | ||
} else if (t.isFunctionExpression(arg)) { | ||
getFunctionParams(arg, deps, filename, programPath); | ||
getFunctionParams(arg, deps, filename, publicPath, programPath); | ||
} | ||
@@ -157,0 +163,0 @@ return deps; |
const { types: t } = require('@babel/core'); | ||
const { extractFunctionParameterTypes } = require('./common'); | ||
const encase = (programPath, path, jpex, filename) => { | ||
const encase = (programPath, path, { identifier, filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
@@ -10,3 +10,3 @@ const args = path.node.arguments; | ||
t.isMemberExpression(callee) && | ||
jpex.includes(callee.object.name) && | ||
identifier.includes(callee.object.name) && | ||
callee.property.name === 'encase' | ||
@@ -24,3 +24,3 @@ ); | ||
const arg = path.get('arguments.0'); | ||
const deps = extractFunctionParameterTypes(programPath, arg, filename); | ||
const deps = extractFunctionParameterTypes(programPath, arg, filename, publicPath); | ||
if (deps.length) { | ||
@@ -27,0 +27,0 @@ path.node.arguments.splice(0, 0, t.arrayExpression(deps.map((dep) => t.stringLiteral(dep)))); |
@@ -11,3 +11,3 @@ const { types: t } = require('@babel/core'); | ||
const factories = (programPath, path, jpex, filename) => { | ||
const factories = (programPath, path, { identifier, filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
@@ -18,3 +18,3 @@ const args = path.node.arguments; | ||
t.isMemberExpression(callee) && | ||
jpex.includes(callee.object.name) && | ||
identifier.includes(callee.object.name) && | ||
FACTORY_METHODS.includes(callee.property.name) | ||
@@ -33,3 +33,3 @@ ); | ||
const name = getConcreteTypeName(type, filename, programPath); | ||
const name = getConcreteTypeName(type, filename, publicPath, programPath); | ||
if (name != null) { | ||
@@ -45,3 +45,3 @@ args.unshift(t.stringLiteral(name)); | ||
const arg = path.get('arguments.1'); | ||
const deps = extractFunctionParameterTypes(programPath, arg, filename); | ||
const deps = extractFunctionParameterTypes(programPath, arg, filename, publicPath); | ||
if (deps.length) { | ||
@@ -48,0 +48,0 @@ path.node.arguments.splice(1, 0, t.arrayExpression(deps.map((dep) => t.stringLiteral(dep)))); |
@@ -20,3 +20,3 @@ const { declare } = require('@babel/helper-plugin-utils'); | ||
} = state; | ||
const filename = publicPath || this | ||
const filename = this | ||
.filename | ||
@@ -28,10 +28,15 @@ .split('.') | ||
identifier = [].concat(identifier); | ||
handleFactoryCalls(programPath, path, identifier, filename); | ||
handleResolveCall(programPath, path, identifier, filename); | ||
handleResolveWithCall(programPath, path, identifier, filename); | ||
handleEncaseCall(programPath, path, identifier, filename); | ||
handleAliasCall(programPath, path, identifier, filename); | ||
handleInferCall(programPath, path, identifier, filename); | ||
handleRawCall(programPath, path, identifier, filename); | ||
handleUseResolve(programPath, path, identifier, filename); | ||
const opts = { | ||
identifier, | ||
filename, | ||
publicPath, | ||
}; | ||
handleFactoryCalls(programPath, path, opts); | ||
handleResolveCall(programPath, path, opts); | ||
handleResolveWithCall(programPath, path, opts); | ||
handleEncaseCall(programPath, path, opts); | ||
handleAliasCall(programPath, path, opts); | ||
handleInferCall(programPath, path, opts); | ||
handleRawCall(programPath, path, opts); | ||
handleUseResolve(programPath, path, opts); | ||
}, | ||
@@ -38,0 +43,0 @@ }; |
@@ -5,9 +5,8 @@ const { types: t } = require('@babel/core'); | ||
const infer = (programPath, path, jpex, filename) => { | ||
const infer = (programPath, path, { identifier, filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
const args = path.node.arguments; | ||
const isJpexCall = ( | ||
t.isMemberExpression(callee) && | ||
jpex.includes(callee.object.name) && | ||
identifier.includes(callee.object.name) && | ||
callee.property.name === 'infer' | ||
@@ -21,3 +20,3 @@ ); | ||
const type = getPath([ 'node', 'typeParameters', 'params', '0' ], path); | ||
const name = getConcreteTypeName(type, filename, programPath); | ||
const name = getConcreteTypeName(type, filename, publicPath, programPath); | ||
@@ -24,0 +23,0 @@ if (name != null) { |
@@ -5,3 +5,3 @@ const { types: t } = require('@babel/core'); | ||
const raw = (programPath, path, jpex, filename) => { | ||
const raw = (programPath, path, { identifier, filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
@@ -12,3 +12,3 @@ const args = path.node.arguments; | ||
t.isMemberExpression(callee) && | ||
jpex.includes(callee.object.name) && | ||
identifier.includes(callee.object.name) && | ||
callee.property.name === 'raw' | ||
@@ -26,3 +26,3 @@ ); | ||
const type = getPath([ 'node', 'typeParameters', 'params', '0' ], path); | ||
const name = getConcreteTypeName(type, filename, programPath); | ||
const name = getConcreteTypeName(type, filename, publicPath, programPath); | ||
if (name != null) { | ||
@@ -29,0 +29,0 @@ args.unshift(t.stringLiteral(name)); |
@@ -5,3 +5,3 @@ const { types: t } = require('@babel/core'); | ||
const resolve = (programPath, path, jpex, filename) => { | ||
const resolve = (programPath, path, { identifier, filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
@@ -12,3 +12,3 @@ const args = path.node.arguments; | ||
t.isMemberExpression(callee) && | ||
jpex.includes(callee.object.name) && | ||
identifier.includes(callee.object.name) && | ||
callee.property.name === 'resolve' | ||
@@ -26,3 +26,3 @@ ); | ||
const type = getPath([ 'node', 'typeParameters', 'params', '0' ], path); | ||
const name = getConcreteTypeName(type, filename, programPath); | ||
const name = getConcreteTypeName(type, filename, publicPath, programPath); | ||
if (name != null) { | ||
@@ -29,0 +29,0 @@ args.unshift(t.stringLiteral(name)); |
@@ -5,3 +5,3 @@ const { types: t } = require('@babel/core'); | ||
const resolveWith = (programPath, path, jpex, filename) => { | ||
const resolveWith = (programPath, path, { identifier, filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
@@ -12,3 +12,3 @@ const args = path.node.arguments; | ||
t.isMemberExpression(callee) && | ||
jpex.includes(callee.object.name) && | ||
identifier.includes(callee.object.name) && | ||
callee.property.name === 'resolveWith' | ||
@@ -25,3 +25,3 @@ ); | ||
const type = getPath([ 'node', 'typeParameters', 'params', '0' ], path); | ||
const name = getConcreteTypeName(type, filename, programPath); | ||
const name = getConcreteTypeName(type, filename, publicPath, programPath); | ||
if (name != null) { | ||
@@ -28,0 +28,0 @@ args.unshift(t.stringLiteral(name)); |
@@ -17,3 +17,3 @@ const { types: t } = require('@babel/core'); | ||
const resolve = (programPath, path, jpex, filename) => { | ||
const resolve = (programPath, path, { filename, publicPath }) => { | ||
const callee = path.node.callee; | ||
@@ -42,3 +42,3 @@ const args = path.node.arguments; | ||
const type = getPath([ 'node', 'typeParameters', 'params', '0' ], path); | ||
const name = getConcreteTypeName(type, filename, programPath); | ||
const name = getConcreteTypeName(type, filename, publicPath, programPath); | ||
if (name != null) { | ||
@@ -45,0 +45,0 @@ args.unshift(t.stringLiteral(name)); |
83551
1970