@vuedx/compiler-tsx
Advanced tools
Comparing version 0.3.1-insiders-1604106530.0 to 0.3.1-insiders-1604576237.0
@@ -7,2 +7,3 @@ 'use strict'; | ||
const templateAstTypes = require('@vuedx/template-ast-types'); | ||
const Path = require('path'); | ||
const parser = require('@babel/parser'); | ||
@@ -14,2 +15,3 @@ const types = require('@babel/types'); | ||
const Path__default = /*#__PURE__*/_interopDefaultLegacy(Path); | ||
const camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase); | ||
@@ -21,3 +23,3 @@ | ||
const hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
return hit !== null && hit !== void 0 ? hit : (cache[str] = fn(str)); | ||
}); | ||
@@ -30,3 +32,3 @@ }; | ||
const camelize = cacheStringFunction((str) => { | ||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')); | ||
return str.replace(camelizeRE, (_, c) => typeof c === 'string' ? c.toUpperCase() : ''); | ||
}); | ||
@@ -56,7 +58,10 @@ /** | ||
pos.line += linesCount; | ||
pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos; | ||
pos.column = | ||
lastNewLinePos === -1 | ||
? pos.column + numberOfCharacters | ||
: numberOfCharacters - lastNewLinePos; | ||
return pos; | ||
} | ||
function createLoc(loc, offset, length) { | ||
if (!loc) | ||
if (loc == null) | ||
return; | ||
@@ -68,2 +73,8 @@ const source = loc.source.substr(offset, length); | ||
} | ||
function getComponentName(fileName) { | ||
return Path__default['default'].posix.basename(fileName).replace(/\.vue$/, ''); | ||
} | ||
function processBogusComment(content) { | ||
return content.replace(/</g, `{'<'}`).replace(/>/g, `{'>'}`); | ||
} | ||
@@ -76,3 +87,3 @@ function createExpressionTracker(addIdentifer) { | ||
!node.content.isStatic && | ||
node.content.content.trim()) { | ||
node.content.content.trim() !== '') { | ||
trackIdentifiers(node.content.content, context, addIdentifer); | ||
@@ -86,10 +97,10 @@ } | ||
!dir.arg.isStatic && | ||
dir.arg.content.trim()) { | ||
dir.arg.content.trim() !== '') { | ||
trackIdentifiers(dir.arg.content, context, addIdentifer); | ||
} | ||
const slot = compilerCore.findDir(node, 'slot'); | ||
if (slot) { | ||
if (slot != null) { | ||
if (templateAstTypes.isSimpleExpressionNode(slot.exp) && | ||
!slot.exp.isStatic && | ||
slot.exp.content.trim()) { | ||
slot.exp.content.trim() !== '') { | ||
trackIdentifiers(slot.exp.content, context, (identifier) => { | ||
@@ -108,3 +119,3 @@ localIdentifiers.add(identifier); | ||
!dir.exp.isStatic && | ||
dir.exp.content.trim()) { | ||
dir.exp.content.trim() !== '') { | ||
context.addIdentifiers('$event'); | ||
@@ -116,3 +127,4 @@ trackIdentifiers(dir.exp.content, context, addIdentifer, false, true); | ||
default: { | ||
if (templateAstTypes.isSimpleExpressionNode(dir.exp) && dir.exp.content.trim()) { | ||
if (templateAstTypes.isSimpleExpressionNode(dir.exp) && | ||
dir.exp.content.trim() !== '') { | ||
trackIdentifiers(dir.exp.content, context, addIdentifer); | ||
@@ -142,2 +154,3 @@ } | ||
asRawStatements = false) { | ||
var _a; | ||
rawExp = rawExp | ||
@@ -149,3 +162,3 @@ .trim() | ||
if (!asParams && | ||
!context.identifiers[rawExp] && | ||
((_a = context.identifiers[rawExp]) !== null && _a !== void 0 ? _a : 0) === 0 && | ||
!isKnownIdentifier(rawExp)) { | ||
@@ -162,3 +175,3 @@ addIdentifer(rawExp); | ||
plugins: ['bigInt', 'optionalChaining', 'nullishCoalescingOperator'], | ||
// @ts-ignore | ||
// @ts-expect-error | ||
errorRecovery: true, | ||
@@ -169,7 +182,7 @@ }); | ||
enter(node, ancestors) { | ||
var _a; | ||
var _a, _b; | ||
const scope = new Set(); | ||
const parent = (_a = ancestors[ancestors.length - 1]) === null || _a === void 0 ? void 0 : _a.node; | ||
if (types.isIdentifier(node)) { | ||
if (!knownIds[node.name]) { | ||
if (((_b = knownIds[node.name]) !== null && _b !== void 0 ? _b : 0) === 0) { | ||
if (shouldTrack(node, parent)) { | ||
@@ -189,2 +202,3 @@ addIdentifer(node.name); | ||
if (!scope.has(id)) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
if (id in knownIds) | ||
@@ -199,9 +213,12 @@ ++knownIds[id]; | ||
} | ||
// @ts-ignore | ||
// @ts-expect-error | ||
node.scope = scope; | ||
}, | ||
exit(node) { | ||
// @ts-ignore | ||
// @ts-expect-error | ||
const scope = node.scope; | ||
scope === null || scope === void 0 ? void 0 : scope.forEach((id) => --knownIds[id]); | ||
scope === null || scope === void 0 ? void 0 : scope.forEach((id) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
--knownIds[id]; | ||
}); | ||
}, | ||
@@ -231,3 +248,3 @@ }); | ||
function isStaticProperty(node) { | ||
return types.isObjectMember(node) && node.computed === false; | ||
return types.isObjectMember(node) && !node.computed; | ||
} | ||
@@ -259,2 +276,3 @@ function isStaticPropertyKey(node, parent) { | ||
} | ||
return false; | ||
} | ||
@@ -268,3 +286,3 @@ | ||
const parseResult = forAliasRE.exec(dir.exp.content); | ||
if (parseResult) { | ||
if (parseResult != null) { | ||
exp = compilerCore.createSimpleExpression(parseResult[2], false, createLoc(dir.exp.loc, dir.exp.content.indexOf(parseResult[2]), parseResult[2].length)); | ||
@@ -275,8 +293,18 @@ trackIdentifiers(exp.content, context, addIdentifer); | ||
return compilerCore.processFor(node, dir, context, (forNode) => { | ||
const renderExp = compilerCore.createCallExpression(context.helper(compilerCore.RENDER_LIST), [exp]); | ||
forNode.codegenNode = renderExp; | ||
const renderExp = compilerCore.createCallExpression(context.helper(compilerCore.RENDER_LIST), [ | ||
exp, | ||
]); | ||
forNode.codegenNode = compilerCore.createCompoundExpression([ | ||
'{', | ||
renderExp, | ||
'}', | ||
]); | ||
return () => { | ||
const childBlock = forNode.children.length === 1 | ||
? forNode.children[0] | ||
: compilerCore.createCompoundExpression(['<>', ...forNode.children, '</>']); | ||
const childBlock = forNode.children.length === 0 | ||
? compilerCore.createCompoundExpression(['null']) | ||
: compilerCore.createCompoundExpression([ | ||
'<>', | ||
...forNode.children, | ||
'</>', | ||
]); | ||
renderExp.arguments.push(compilerCore.createFunctionExpression(compilerCore.createForLoopParams(forNode.parseResult), childBlock, true /* force newline */)); | ||
@@ -302,3 +330,3 @@ }; | ||
return this.bindings[identifier]; | ||
if (this.parent) { | ||
if (this.parent != null) { | ||
return (this.bindings[identifier] = this.parent.getBinding(identifier)); | ||
@@ -318,7 +346,7 @@ } | ||
templateAstTypes.traverse(ast, (node, ancestors) => { | ||
var _a; | ||
const parent = ((_a = ancestors[ancestors.length - 1]) === null || _a === void 0 ? void 0 : _a.node) || ast; | ||
const scope = (node.scope = node.scope || new Scope(parent.scope)); | ||
var _a, _b, _c; | ||
const parent = ((_b = (_a = ancestors[ancestors.length - 1]) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : ast); | ||
const scope = (node.scope = (_c = node.scope) !== null && _c !== void 0 ? _c : new Scope(parent.scope)); | ||
if (templateAstTypes.isSimpleExpressionNode(node) && !node.isStatic) { | ||
if (!parent || | ||
if (parent != null || | ||
!(templateAstTypes.isDirectiveNode(parent) && | ||
@@ -332,4 +360,5 @@ ['slot', 'for'].includes(parent.name) && | ||
node.props.forEach((prop) => { | ||
var _a; | ||
if (templateAstTypes.isDirectiveNode(prop)) { | ||
const directiveScope = (prop.scope = prop.scope || new Scope(scope)); | ||
const directiveScope = (prop.scope = (_a = prop.scope) !== null && _a !== void 0 ? _a : new Scope(scope)); | ||
if (prop.name === 'slot') { | ||
@@ -349,3 +378,3 @@ if (templateAstTypes.isSimpleExpressionNode(prop.exp)) { | ||
const match = forAliasRE.exec(prop.exp.content); | ||
if (match) { | ||
if (match != null) { | ||
const [, LHS, RHS] = match; | ||
@@ -381,3 +410,3 @@ getIdentifiers(RHS).forEach((identifier) => { | ||
if (types.isIdentifier(node)) { | ||
if (ancestors.length) { | ||
if (ancestors.length > 0) { | ||
if (shouldTrack$1(node, ancestors[ancestors.length - 1].node)) { | ||
@@ -402,3 +431,3 @@ identifers.add(node.name); | ||
plugins: ['bigInt', 'optionalChaining'], | ||
// @ts-ignore | ||
// @ts-expect-error | ||
errorRecovery: true, | ||
@@ -410,3 +439,3 @@ }); | ||
plugins: ['bigInt', 'optionalChaining'], | ||
// @ts-ignore | ||
// @ts-expect-error | ||
errorRecovery: true, | ||
@@ -434,2 +463,3 @@ }); | ||
} | ||
return false; | ||
} | ||
@@ -440,2 +470,3 @@ | ||
return (node, context) => { | ||
var _a; | ||
if (!isImportAdded) { | ||
@@ -453,7 +484,7 @@ context.imports.add({ | ||
const component = options.components[name]; | ||
if (!context.identifiers[name]) { | ||
if (component) { | ||
if (((_a = context.identifiers[name]) !== null && _a !== void 0 ? _a : 0) <= 0) { | ||
if (component != null) { | ||
context.imports.add({ | ||
exp: component.named | ||
? `{ ${component.name ? component.name + ' as ' : ''}${name} }` | ||
exp: component.named === true | ||
? `{ ${component.name != null ? component.name + ' as ' : ''}${name} }` | ||
: name, | ||
@@ -467,6 +498,6 @@ path: component.path, | ||
return () => { | ||
let name = templateAstTypes.isComponentNode(node) ? pascalCase(node.tag) : node.tag; | ||
const startTag = name | ||
? compilerCore.createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.indexOf(node.tag), node.tag.length), false) | ||
const name = templateAstTypes.isComponentNode(node) | ||
? pascalCase(node.tag) | ||
: node.tag; | ||
const startTag = compilerCore.createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.indexOf(node.tag), node.tag.length), false); | ||
const attributes = getJSXAttributes(node); | ||
@@ -478,9 +509,7 @@ if (node.isSelfClosing) { | ||
...attributes, | ||
'/>', | ||
' />', | ||
]); | ||
} | ||
else { | ||
const endTag = name | ||
? compilerCore.createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.lastIndexOf(node.tag), node.tag.length), false) | ||
: node.tag; | ||
const endTag = compilerCore.createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.lastIndexOf(node.tag), node.tag.length), false); | ||
const children = getChildren(node, context); | ||
@@ -491,3 +520,3 @@ node.codegenNode = compilerCore.createCompoundExpression([ | ||
...attributes, | ||
'>', | ||
' >', | ||
...children, | ||
@@ -503,3 +532,4 @@ '</', | ||
function getInternalPath(options) { | ||
return `./${options.filename.split(/[/\\]/).pop()}?internal`; | ||
var _a; | ||
return `./${(_a = options.filename.split(/[/\\]/).pop()) !== null && _a !== void 0 ? _a : options.filename}?internal`; | ||
} | ||
@@ -509,14 +539,15 @@ function getJSXAttributes(node, context) { | ||
node.props.forEach((dir, index) => { | ||
var _a; | ||
if (templateAstTypes.isAttributeNode(dir)) { | ||
result.push(' ', compilerCore.createSimpleExpression(dir.name, false, createLoc(dir.loc, 0, dir.name.length))); | ||
if (dir.value) { | ||
if (dir.value != null) { | ||
result.push('=', compilerCore.createSimpleExpression(dir.value.loc.source, false, dir.value.loc)); | ||
} | ||
} | ||
else if ('bind' === dir.name) { | ||
else if (dir.name === 'bind') { | ||
if (templateAstTypes.isSimpleExpressionNode(dir.arg)) { | ||
if (dir.arg.isStatic || dir.arg.content === 'key') { | ||
dir.arg.isStatic = false; | ||
result.push(' ', dir.arg.content === 'class' ? 'className' : dir.arg); | ||
if (dir.exp) | ||
result.push(' ', dir.arg); | ||
if (dir.exp != null) | ||
result.push('={', dir.exp, '}'); | ||
@@ -526,3 +557,3 @@ } | ||
result.push(' {...({[', dir.arg, ']: '); | ||
if (dir.exp) | ||
if (dir.exp != null) | ||
result.push(dir.exp); | ||
@@ -534,7 +565,7 @@ else | ||
} | ||
else if (dir.exp) { | ||
else if (dir.exp != null) { | ||
result.push(' {...(', dir.exp, ')}'); | ||
} | ||
} | ||
else if ('on' === dir.name) { | ||
else if (dir.name === 'on') { | ||
const exp = templateAstTypes.isSimpleExpressionNode(dir.exp) | ||
@@ -556,3 +587,3 @@ ? compilerCore.isSimpleIdentifier(dir.exp.content.trim()) | ||
} | ||
else if (dir.exp) { | ||
else if (dir.exp != null) { | ||
result.push('{...(', dir.exp, ')}'); | ||
@@ -562,3 +593,3 @@ } | ||
else if (dir.name === 'model') { | ||
const exp = dir.exp || 'null'; | ||
const exp = (_a = dir.exp) !== null && _a !== void 0 ? _a : 'null'; | ||
result.push(' '); | ||
@@ -591,3 +622,3 @@ if (templateAstTypes.isSimpleExpressionNode(dir.arg)) { | ||
result.push(dir.arg, ','); | ||
if (dir.exp) | ||
if (dir.exp != null) | ||
result.push(dir.exp, ','); | ||
@@ -601,7 +632,6 @@ result.push(']}'); | ||
if (templateAstTypes.isComponentNode(node)) { | ||
const { slots } = compilerCore.buildSlots(node, context, (props, children) => compilerCore.createFunctionExpression(props, compilerCore.createCompoundExpression([ | ||
'(<>', | ||
...processTemplateNodes(children), | ||
'</>)', | ||
]))); | ||
const { slots } = compilerCore.buildSlots(node, context, (props, children) => { | ||
const nodes = processTemplateNodes(children); | ||
return compilerCore.createFunctionExpression(props, compilerCore.createCompoundExpression(nodes.length > 0 ? ['(<>', ...nodes, '</>)'] : ['null'])); | ||
}); | ||
context.helpers.delete(compilerCore.WITH_CTX); | ||
@@ -621,6 +651,14 @@ if (isDynamicSlotsExpression(slots)) { | ||
function processTemplateNodes(nodes) { | ||
return nodes.map((node) => { | ||
if (templateAstTypes.isTextNode(node)) { | ||
return compilerCore.createSimpleExpression(node.content, false, undefined, false); | ||
return nodes.flatMap((node) => { | ||
if (templateAstTypes.isCommentNode(node)) { | ||
if (node.content.includes('<') || node.content.includes('>')) { | ||
return compilerCore.createCompoundExpression([processBogusComment(node.content)]); | ||
} | ||
else { | ||
return []; | ||
} | ||
} | ||
else if (templateAstTypes.isTextNode(node)) { | ||
return compilerCore.createCompoundExpression([processBogusComment(node.content)]); | ||
} | ||
else if (templateAstTypes.isIfNode(node) || templateAstTypes.isForNode(node)) { | ||
@@ -659,2 +697,5 @@ return compilerCore.createCompoundExpression(['{', node, '}']); | ||
...options.components, | ||
[getComponentName(options.filename)]: { | ||
path: `./${Path__default['default'].posix.basename(options.filename)}`, | ||
}, | ||
}, | ||
@@ -684,3 +725,3 @@ }; | ||
if (templateAstTypes.isDirectiveNode(prop)) { | ||
if (prop.exp) { | ||
if (prop.exp != null) { | ||
expressions.push([ | ||
@@ -704,4 +745,19 @@ prop.exp.loc.start.offset, | ||
if (templateAstTypes.isCommentNode(node)) { | ||
context.removeNode(node); | ||
if (node.content.includes('<') || node.content.includes('>')) { | ||
context.replaceNode(compilerCore.createCompoundExpression([ | ||
processBogusComment(node.content.trim()), | ||
])); | ||
} | ||
else { | ||
context.removeNode(node); | ||
} | ||
} | ||
else if (templateAstTypes.isTextNode(node)) { | ||
context.replaceNode(compilerCore.createCompoundExpression([processBogusComment(node.content)])); | ||
} | ||
else if (templateAstTypes.isElementNode(node) && node.tag.includes('<')) { | ||
context.replaceNode(compilerCore.createCompoundExpression([ | ||
processBogusComment(node.loc.source.trim()), | ||
])); | ||
} | ||
}, | ||
@@ -722,3 +778,3 @@ createTransformFor((id) => identifiers.add(id)), | ||
}); | ||
if (ast.children.length > 1) { | ||
if (ast.children.length > 0) { | ||
ast.codegenNode = compilerCore.createCompoundExpression([ | ||
@@ -732,5 +788,3 @@ '/*@@vue:start*/<>', | ||
ast.codegenNode = compilerCore.createCompoundExpression([ | ||
'/*@@vue:start*/', | ||
...ast.children, | ||
'/*@@vue:end*/', | ||
'/*@@vue:start*/null/*@@vue:end*/', | ||
]); | ||
@@ -746,8 +800,16 @@ } | ||
context.push = (code, node) => { | ||
if (templateAstTypes.isSimpleExpressionNode(node) && | ||
node.loc && | ||
node.loc.start.offset < node.loc.end.offset) { | ||
if (code.startsWith('export ')) { | ||
push([ | ||
'declare const __completionsTrigger: InstanceType<typeof _Ctx>', | ||
'__completionsTrigger./*@@vue:completions*/$props', | ||
'const __completionsTag = /*@@vue:completionsTag*/<div />', | ||
'', | ||
].join('\n')); | ||
} | ||
if ((node === null || node === void 0 ? void 0 : node.loc) != null && | ||
node.loc.start.offset !== 0 && | ||
node.loc.end.offset !== 0) { | ||
mappings.push([ | ||
context.offset, | ||
node.content.length, | ||
code.length, | ||
node.loc.start.offset, | ||
@@ -759,3 +821,3 @@ node.loc.source.length, | ||
if (code.startsWith('function render(_ctx, _cache')) { | ||
push(`function render(${identifiers.size | ||
push(`function render(${identifiers.size > 0 | ||
? `{${Array.from(identifiers).join(', ')}}` | ||
@@ -762,0 +824,0 @@ : '_ctx'}: InstanceType<typeof _Ctx>) {`); |
@@ -35,3 +35,3 @@ import { Node, CodegenResult as CodegenResult$1, CompilerError, CompilerOptions } from '@vue/compiler-core'; | ||
*/ | ||
expressions: [number, number][]; | ||
expressions: Array<[number, number]>; | ||
/** | ||
@@ -42,3 +42,3 @@ * Each tuple represents an simple expression (mostly identifier). | ||
*/ | ||
mappings: [number, number, number, number, number][]; | ||
mappings: Array<[number, number, number, number, number]>; | ||
} | ||
@@ -45,0 +45,0 @@ |
import { findDir, isSimpleIdentifier, createStructuralDirectiveTransform, createSimpleExpression, processFor, createCallExpression, RENDER_LIST, createCompoundExpression, createFunctionExpression, createForLoopParams, buildSlots, WITH_CTX, baseParse, transform, OPEN_BLOCK, CREATE_BLOCK, CREATE_VNODE, FRAGMENT, generate } from '@vue/compiler-core'; | ||
import { isInterpolationNode, isSimpleExpressionNode, isElementNode, isDirectiveNode, traverse as traverse$1, isComponentNode, isAttributeNode, isTextNode, isIfNode, isForNode, isCommentNode } from '@vuedx/template-ast-types'; | ||
import { isInterpolationNode, isSimpleExpressionNode, isElementNode, isDirectiveNode, traverse as traverse$1, isComponentNode, isAttributeNode, isCommentNode, isTextNode, isIfNode, isForNode } from '@vuedx/template-ast-types'; | ||
import Path from 'path'; | ||
import { parse, parseExpression } from '@babel/parser'; | ||
@@ -11,3 +12,3 @@ import { traverse, isIdentifier, isFunction, traverseFast, isObjectMember, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isArrayPattern } from '@babel/types'; | ||
const hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
return hit !== null && hit !== void 0 ? hit : (cache[str] = fn(str)); | ||
}); | ||
@@ -20,3 +21,3 @@ }; | ||
const camelize = cacheStringFunction((str) => { | ||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')); | ||
return str.replace(camelizeRE, (_, c) => typeof c === 'string' ? c.toUpperCase() : ''); | ||
}); | ||
@@ -46,7 +47,10 @@ /** | ||
pos.line += linesCount; | ||
pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos; | ||
pos.column = | ||
lastNewLinePos === -1 | ||
? pos.column + numberOfCharacters | ||
: numberOfCharacters - lastNewLinePos; | ||
return pos; | ||
} | ||
function createLoc(loc, offset, length) { | ||
if (!loc) | ||
if (loc == null) | ||
return; | ||
@@ -58,2 +62,8 @@ const source = loc.source.substr(offset, length); | ||
} | ||
function getComponentName(fileName) { | ||
return Path.posix.basename(fileName).replace(/\.vue$/, ''); | ||
} | ||
function processBogusComment(content) { | ||
return content.replace(/</g, `{'<'}`).replace(/>/g, `{'>'}`); | ||
} | ||
@@ -66,3 +76,3 @@ function createExpressionTracker(addIdentifer) { | ||
!node.content.isStatic && | ||
node.content.content.trim()) { | ||
node.content.content.trim() !== '') { | ||
trackIdentifiers(node.content.content, context, addIdentifer); | ||
@@ -76,10 +86,10 @@ } | ||
!dir.arg.isStatic && | ||
dir.arg.content.trim()) { | ||
dir.arg.content.trim() !== '') { | ||
trackIdentifiers(dir.arg.content, context, addIdentifer); | ||
} | ||
const slot = findDir(node, 'slot'); | ||
if (slot) { | ||
if (slot != null) { | ||
if (isSimpleExpressionNode(slot.exp) && | ||
!slot.exp.isStatic && | ||
slot.exp.content.trim()) { | ||
slot.exp.content.trim() !== '') { | ||
trackIdentifiers(slot.exp.content, context, (identifier) => { | ||
@@ -98,3 +108,3 @@ localIdentifiers.add(identifier); | ||
!dir.exp.isStatic && | ||
dir.exp.content.trim()) { | ||
dir.exp.content.trim() !== '') { | ||
context.addIdentifiers('$event'); | ||
@@ -106,3 +116,4 @@ trackIdentifiers(dir.exp.content, context, addIdentifer, false, true); | ||
default: { | ||
if (isSimpleExpressionNode(dir.exp) && dir.exp.content.trim()) { | ||
if (isSimpleExpressionNode(dir.exp) && | ||
dir.exp.content.trim() !== '') { | ||
trackIdentifiers(dir.exp.content, context, addIdentifer); | ||
@@ -132,2 +143,3 @@ } | ||
asRawStatements = false) { | ||
var _a; | ||
rawExp = rawExp | ||
@@ -139,3 +151,3 @@ .trim() | ||
if (!asParams && | ||
!context.identifiers[rawExp] && | ||
((_a = context.identifiers[rawExp]) !== null && _a !== void 0 ? _a : 0) === 0 && | ||
!isKnownIdentifier(rawExp)) { | ||
@@ -152,3 +164,3 @@ addIdentifer(rawExp); | ||
plugins: ['bigInt', 'optionalChaining', 'nullishCoalescingOperator'], | ||
// @ts-ignore | ||
// @ts-expect-error | ||
errorRecovery: true, | ||
@@ -159,7 +171,7 @@ }); | ||
enter(node, ancestors) { | ||
var _a; | ||
var _a, _b; | ||
const scope = new Set(); | ||
const parent = (_a = ancestors[ancestors.length - 1]) === null || _a === void 0 ? void 0 : _a.node; | ||
if (isIdentifier(node)) { | ||
if (!knownIds[node.name]) { | ||
if (((_b = knownIds[node.name]) !== null && _b !== void 0 ? _b : 0) === 0) { | ||
if (shouldTrack(node, parent)) { | ||
@@ -179,2 +191,3 @@ addIdentifer(node.name); | ||
if (!scope.has(id)) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
if (id in knownIds) | ||
@@ -189,9 +202,12 @@ ++knownIds[id]; | ||
} | ||
// @ts-ignore | ||
// @ts-expect-error | ||
node.scope = scope; | ||
}, | ||
exit(node) { | ||
// @ts-ignore | ||
// @ts-expect-error | ||
const scope = node.scope; | ||
scope === null || scope === void 0 ? void 0 : scope.forEach((id) => --knownIds[id]); | ||
scope === null || scope === void 0 ? void 0 : scope.forEach((id) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
--knownIds[id]; | ||
}); | ||
}, | ||
@@ -221,3 +237,3 @@ }); | ||
function isStaticProperty(node) { | ||
return isObjectMember(node) && node.computed === false; | ||
return isObjectMember(node) && !node.computed; | ||
} | ||
@@ -249,2 +265,3 @@ function isStaticPropertyKey(node, parent) { | ||
} | ||
return false; | ||
} | ||
@@ -258,3 +275,3 @@ | ||
const parseResult = forAliasRE.exec(dir.exp.content); | ||
if (parseResult) { | ||
if (parseResult != null) { | ||
exp = createSimpleExpression(parseResult[2], false, createLoc(dir.exp.loc, dir.exp.content.indexOf(parseResult[2]), parseResult[2].length)); | ||
@@ -265,8 +282,18 @@ trackIdentifiers(exp.content, context, addIdentifer); | ||
return processFor(node, dir, context, (forNode) => { | ||
const renderExp = createCallExpression(context.helper(RENDER_LIST), [exp]); | ||
forNode.codegenNode = renderExp; | ||
const renderExp = createCallExpression(context.helper(RENDER_LIST), [ | ||
exp, | ||
]); | ||
forNode.codegenNode = createCompoundExpression([ | ||
'{', | ||
renderExp, | ||
'}', | ||
]); | ||
return () => { | ||
const childBlock = forNode.children.length === 1 | ||
? forNode.children[0] | ||
: createCompoundExpression(['<>', ...forNode.children, '</>']); | ||
const childBlock = forNode.children.length === 0 | ||
? createCompoundExpression(['null']) | ||
: createCompoundExpression([ | ||
'<>', | ||
...forNode.children, | ||
'</>', | ||
]); | ||
renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */)); | ||
@@ -292,3 +319,3 @@ }; | ||
return this.bindings[identifier]; | ||
if (this.parent) { | ||
if (this.parent != null) { | ||
return (this.bindings[identifier] = this.parent.getBinding(identifier)); | ||
@@ -308,7 +335,7 @@ } | ||
traverse$1(ast, (node, ancestors) => { | ||
var _a; | ||
const parent = ((_a = ancestors[ancestors.length - 1]) === null || _a === void 0 ? void 0 : _a.node) || ast; | ||
const scope = (node.scope = node.scope || new Scope(parent.scope)); | ||
var _a, _b, _c; | ||
const parent = ((_b = (_a = ancestors[ancestors.length - 1]) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : ast); | ||
const scope = (node.scope = (_c = node.scope) !== null && _c !== void 0 ? _c : new Scope(parent.scope)); | ||
if (isSimpleExpressionNode(node) && !node.isStatic) { | ||
if (!parent || | ||
if (parent != null || | ||
!(isDirectiveNode(parent) && | ||
@@ -322,4 +349,5 @@ ['slot', 'for'].includes(parent.name) && | ||
node.props.forEach((prop) => { | ||
var _a; | ||
if (isDirectiveNode(prop)) { | ||
const directiveScope = (prop.scope = prop.scope || new Scope(scope)); | ||
const directiveScope = (prop.scope = (_a = prop.scope) !== null && _a !== void 0 ? _a : new Scope(scope)); | ||
if (prop.name === 'slot') { | ||
@@ -339,3 +367,3 @@ if (isSimpleExpressionNode(prop.exp)) { | ||
const match = forAliasRE.exec(prop.exp.content); | ||
if (match) { | ||
if (match != null) { | ||
const [, LHS, RHS] = match; | ||
@@ -371,3 +399,3 @@ getIdentifiers(RHS).forEach((identifier) => { | ||
if (isIdentifier(node)) { | ||
if (ancestors.length) { | ||
if (ancestors.length > 0) { | ||
if (shouldTrack$1(node, ancestors[ancestors.length - 1].node)) { | ||
@@ -392,3 +420,3 @@ identifers.add(node.name); | ||
plugins: ['bigInt', 'optionalChaining'], | ||
// @ts-ignore | ||
// @ts-expect-error | ||
errorRecovery: true, | ||
@@ -400,3 +428,3 @@ }); | ||
plugins: ['bigInt', 'optionalChaining'], | ||
// @ts-ignore | ||
// @ts-expect-error | ||
errorRecovery: true, | ||
@@ -424,2 +452,3 @@ }); | ||
} | ||
return false; | ||
} | ||
@@ -430,2 +459,3 @@ | ||
return (node, context) => { | ||
var _a; | ||
if (!isImportAdded) { | ||
@@ -443,7 +473,7 @@ context.imports.add({ | ||
const component = options.components[name]; | ||
if (!context.identifiers[name]) { | ||
if (component) { | ||
if (((_a = context.identifiers[name]) !== null && _a !== void 0 ? _a : 0) <= 0) { | ||
if (component != null) { | ||
context.imports.add({ | ||
exp: component.named | ||
? `{ ${component.name ? component.name + ' as ' : ''}${name} }` | ||
exp: component.named === true | ||
? `{ ${component.name != null ? component.name + ' as ' : ''}${name} }` | ||
: name, | ||
@@ -457,6 +487,6 @@ path: component.path, | ||
return () => { | ||
let name = isComponentNode(node) ? pascalCase(node.tag) : node.tag; | ||
const startTag = name | ||
? createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.indexOf(node.tag), node.tag.length), false) | ||
const name = isComponentNode(node) | ||
? pascalCase(node.tag) | ||
: node.tag; | ||
const startTag = createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.indexOf(node.tag), node.tag.length), false); | ||
const attributes = getJSXAttributes(node); | ||
@@ -468,9 +498,7 @@ if (node.isSelfClosing) { | ||
...attributes, | ||
'/>', | ||
' />', | ||
]); | ||
} | ||
else { | ||
const endTag = name | ||
? createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.lastIndexOf(node.tag), node.tag.length), false) | ||
: node.tag; | ||
const endTag = createSimpleExpression(name, false, createLoc(node.loc, node.loc.source.lastIndexOf(node.tag), node.tag.length), false); | ||
const children = getChildren(node, context); | ||
@@ -481,3 +509,3 @@ node.codegenNode = createCompoundExpression([ | ||
...attributes, | ||
'>', | ||
' >', | ||
...children, | ||
@@ -493,3 +521,4 @@ '</', | ||
function getInternalPath(options) { | ||
return `./${options.filename.split(/[/\\]/).pop()}?internal`; | ||
var _a; | ||
return `./${(_a = options.filename.split(/[/\\]/).pop()) !== null && _a !== void 0 ? _a : options.filename}?internal`; | ||
} | ||
@@ -499,14 +528,15 @@ function getJSXAttributes(node, context) { | ||
node.props.forEach((dir, index) => { | ||
var _a; | ||
if (isAttributeNode(dir)) { | ||
result.push(' ', createSimpleExpression(dir.name, false, createLoc(dir.loc, 0, dir.name.length))); | ||
if (dir.value) { | ||
if (dir.value != null) { | ||
result.push('=', createSimpleExpression(dir.value.loc.source, false, dir.value.loc)); | ||
} | ||
} | ||
else if ('bind' === dir.name) { | ||
else if (dir.name === 'bind') { | ||
if (isSimpleExpressionNode(dir.arg)) { | ||
if (dir.arg.isStatic || dir.arg.content === 'key') { | ||
dir.arg.isStatic = false; | ||
result.push(' ', dir.arg.content === 'class' ? 'className' : dir.arg); | ||
if (dir.exp) | ||
result.push(' ', dir.arg); | ||
if (dir.exp != null) | ||
result.push('={', dir.exp, '}'); | ||
@@ -516,3 +546,3 @@ } | ||
result.push(' {...({[', dir.arg, ']: '); | ||
if (dir.exp) | ||
if (dir.exp != null) | ||
result.push(dir.exp); | ||
@@ -524,7 +554,7 @@ else | ||
} | ||
else if (dir.exp) { | ||
else if (dir.exp != null) { | ||
result.push(' {...(', dir.exp, ')}'); | ||
} | ||
} | ||
else if ('on' === dir.name) { | ||
else if (dir.name === 'on') { | ||
const exp = isSimpleExpressionNode(dir.exp) | ||
@@ -546,3 +576,3 @@ ? isSimpleIdentifier(dir.exp.content.trim()) | ||
} | ||
else if (dir.exp) { | ||
else if (dir.exp != null) { | ||
result.push('{...(', dir.exp, ')}'); | ||
@@ -552,3 +582,3 @@ } | ||
else if (dir.name === 'model') { | ||
const exp = dir.exp || 'null'; | ||
const exp = (_a = dir.exp) !== null && _a !== void 0 ? _a : 'null'; | ||
result.push(' '); | ||
@@ -581,3 +611,3 @@ if (isSimpleExpressionNode(dir.arg)) { | ||
result.push(dir.arg, ','); | ||
if (dir.exp) | ||
if (dir.exp != null) | ||
result.push(dir.exp, ','); | ||
@@ -591,7 +621,6 @@ result.push(']}'); | ||
if (isComponentNode(node)) { | ||
const { slots } = buildSlots(node, context, (props, children) => createFunctionExpression(props, createCompoundExpression([ | ||
'(<>', | ||
...processTemplateNodes(children), | ||
'</>)', | ||
]))); | ||
const { slots } = buildSlots(node, context, (props, children) => { | ||
const nodes = processTemplateNodes(children); | ||
return createFunctionExpression(props, createCompoundExpression(nodes.length > 0 ? ['(<>', ...nodes, '</>)'] : ['null'])); | ||
}); | ||
context.helpers.delete(WITH_CTX); | ||
@@ -611,6 +640,14 @@ if (isDynamicSlotsExpression(slots)) { | ||
function processTemplateNodes(nodes) { | ||
return nodes.map((node) => { | ||
if (isTextNode(node)) { | ||
return createSimpleExpression(node.content, false, undefined, false); | ||
return nodes.flatMap((node) => { | ||
if (isCommentNode(node)) { | ||
if (node.content.includes('<') || node.content.includes('>')) { | ||
return createCompoundExpression([processBogusComment(node.content)]); | ||
} | ||
else { | ||
return []; | ||
} | ||
} | ||
else if (isTextNode(node)) { | ||
return createCompoundExpression([processBogusComment(node.content)]); | ||
} | ||
else if (isIfNode(node) || isForNode(node)) { | ||
@@ -649,2 +686,5 @@ return createCompoundExpression(['{', node, '}']); | ||
...options.components, | ||
[getComponentName(options.filename)]: { | ||
path: `./${Path.posix.basename(options.filename)}`, | ||
}, | ||
}, | ||
@@ -674,3 +714,3 @@ }; | ||
if (isDirectiveNode(prop)) { | ||
if (prop.exp) { | ||
if (prop.exp != null) { | ||
expressions.push([ | ||
@@ -694,4 +734,19 @@ prop.exp.loc.start.offset, | ||
if (isCommentNode(node)) { | ||
context.removeNode(node); | ||
if (node.content.includes('<') || node.content.includes('>')) { | ||
context.replaceNode(createCompoundExpression([ | ||
processBogusComment(node.content.trim()), | ||
])); | ||
} | ||
else { | ||
context.removeNode(node); | ||
} | ||
} | ||
else if (isTextNode(node)) { | ||
context.replaceNode(createCompoundExpression([processBogusComment(node.content)])); | ||
} | ||
else if (isElementNode(node) && node.tag.includes('<')) { | ||
context.replaceNode(createCompoundExpression([ | ||
processBogusComment(node.loc.source.trim()), | ||
])); | ||
} | ||
}, | ||
@@ -712,3 +767,3 @@ createTransformFor((id) => identifiers.add(id)), | ||
}); | ||
if (ast.children.length > 1) { | ||
if (ast.children.length > 0) { | ||
ast.codegenNode = createCompoundExpression([ | ||
@@ -722,5 +777,3 @@ '/*@@vue:start*/<>', | ||
ast.codegenNode = createCompoundExpression([ | ||
'/*@@vue:start*/', | ||
...ast.children, | ||
'/*@@vue:end*/', | ||
'/*@@vue:start*/null/*@@vue:end*/', | ||
]); | ||
@@ -736,8 +789,16 @@ } | ||
context.push = (code, node) => { | ||
if (isSimpleExpressionNode(node) && | ||
node.loc && | ||
node.loc.start.offset < node.loc.end.offset) { | ||
if (code.startsWith('export ')) { | ||
push([ | ||
'declare const __completionsTrigger: InstanceType<typeof _Ctx>', | ||
'__completionsTrigger./*@@vue:completions*/$props', | ||
'const __completionsTag = /*@@vue:completionsTag*/<div />', | ||
'', | ||
].join('\n')); | ||
} | ||
if ((node === null || node === void 0 ? void 0 : node.loc) != null && | ||
node.loc.start.offset !== 0 && | ||
node.loc.end.offset !== 0) { | ||
mappings.push([ | ||
context.offset, | ||
node.content.length, | ||
code.length, | ||
node.loc.start.offset, | ||
@@ -749,3 +810,3 @@ node.loc.source.length, | ||
if (code.startsWith('function render(_ctx, _cache')) { | ||
push(`function render(${identifiers.size | ||
push(`function render(${identifiers.size > 0 | ||
? `{${Array.from(identifiers).join(', ')}}` | ||
@@ -752,0 +813,0 @@ : '_ctx'}: InstanceType<typeof _Ctx>) {`); |
{ | ||
"name": "@vuedx/compiler-tsx", | ||
"version": "0.3.1-insiders-1604106530.0", | ||
"version": "0.3.1-insiders-1604576237.0", | ||
"description": "", | ||
@@ -18,3 +18,3 @@ "main": "dist/index.cjs.js", | ||
"@vue/compiler-core": "^3.0.1", | ||
"@vuedx/template-ast-types": "0.3.1-insiders-1604106530.0", | ||
"@vuedx/template-ast-types": "0.3.1-insiders-1604576237.0", | ||
"lodash.camelcase": "^4.3.0" | ||
@@ -24,4 +24,4 @@ }, | ||
"@types/lodash.camelcase": "^4.3.6", | ||
"@vuedx/analyze": "^0.2.4-0", | ||
"@vuedx/compiler-sfc": "^0.0.0", | ||
"@vuedx/analyze": "0.3.1-insiders-1604576237.0", | ||
"@vuedx/compiler-sfc": "0.3.1-insiders-1604576237.0", | ||
"chalk": "^4.1.0", | ||
@@ -28,0 +28,0 @@ "cli-highlight": "^2.1.4", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
180710
1599
0
+ Added@vuedx/template-ast-types@0.3.1-insiders-1604576237.0(transitive)
- Removed@vuedx/template-ast-types@0.3.1-insiders-1604106530.0(transitive)
Updated@vuedx/template-ast-types@0.3.1-insiders-1604576237.0