refactor: cleanup unused variables in vFor
This commit is contained in:
parent
06c890c336
commit
4c3e7e331a
@ -1,5 +1,5 @@
|
|||||||
import { createDirectiveTransform, TransformContext } from '../transform'
|
import { createDirectiveTransform } from '../transform'
|
||||||
import { NodeTypes, ExpressionNode, Node, SourceLocation } from '../ast'
|
import { NodeTypes, ExpressionNode, Node } from '../ast'
|
||||||
import { createCompilerError, ErrorCodes } from '../errors'
|
import { createCompilerError, ErrorCodes } from '../errors'
|
||||||
import { getInnerRange } from '../utils'
|
import { getInnerRange } from '../utils'
|
||||||
|
|
||||||
@ -16,16 +16,13 @@ export const transformFor = createDirectiveTransform(
|
|||||||
context.replaceNode({
|
context.replaceNode({
|
||||||
type: NodeTypes.FOR,
|
type: NodeTypes.FOR,
|
||||||
loc: node.loc,
|
loc: node.loc,
|
||||||
source: createExpression(aliases.source, dir.exp, context),
|
source: maybeCreateExpression(
|
||||||
valueAlias: aliases.value
|
aliases.source,
|
||||||
? createExpression(aliases.value, dir.exp, context)
|
dir.exp
|
||||||
: undefined,
|
) as ExpressionNode,
|
||||||
keyAlias: aliases.key
|
valueAlias: maybeCreateExpression(aliases.value, dir.exp),
|
||||||
? createExpression(aliases.key, dir.exp, context)
|
keyAlias: maybeCreateExpression(aliases.key, dir.exp),
|
||||||
: undefined,
|
objectIndexAlias: maybeCreateExpression(aliases.index, dir.exp),
|
||||||
objectIndexAlias: aliases.index
|
|
||||||
? createExpression(aliases.index, dir.exp, context)
|
|
||||||
: undefined,
|
|
||||||
children: [node]
|
children: [node]
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -44,25 +41,6 @@ export const transformFor = createDirectiveTransform(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
function createExpression(
|
|
||||||
alias: AliasExpression,
|
|
||||||
node: Node,
|
|
||||||
context: TransformContext
|
|
||||||
): ExpressionNode {
|
|
||||||
const loc: SourceLocation = getInnerRange(
|
|
||||||
node.loc,
|
|
||||||
alias.offset,
|
|
||||||
alias.content.length
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: NodeTypes.EXPRESSION,
|
|
||||||
loc: loc,
|
|
||||||
content: alias.content,
|
|
||||||
isStatic: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AliasExpression {
|
interface AliasExpression {
|
||||||
offset: number
|
offset: number
|
||||||
content: string
|
content: string
|
||||||
@ -75,13 +53,11 @@ interface AliasExpressions {
|
|||||||
index: AliasExpression | undefined
|
index: AliasExpression | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseAliasExpressions(source: string): null | AliasExpressions {
|
function parseAliasExpressions(source: string): AliasExpressions | null {
|
||||||
const inMatch = source.match(forAliasRE)
|
const inMatch = source.match(forAliasRE)
|
||||||
|
|
||||||
if (!inMatch) return null
|
if (!inMatch) return null
|
||||||
|
|
||||||
const [, LHS, RHS] = inMatch
|
const [, LHS, RHS] = inMatch
|
||||||
|
|
||||||
const result: AliasExpressions = {
|
const result: AliasExpressions = {
|
||||||
source: {
|
source: {
|
||||||
offset: source.indexOf(RHS, LHS.length),
|
offset: source.indexOf(RHS, LHS.length),
|
||||||
@ -135,3 +111,17 @@ function parseAliasExpressions(source: string): null | AliasExpressions {
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeCreateExpression(
|
||||||
|
alias: AliasExpression | undefined,
|
||||||
|
node: Node
|
||||||
|
): ExpressionNode | undefined {
|
||||||
|
if (alias) {
|
||||||
|
return {
|
||||||
|
type: NodeTypes.EXPRESSION,
|
||||||
|
loc: getInnerRange(node.loc, alias.offset, alias.content.length),
|
||||||
|
content: alias.content,
|
||||||
|
isStatic: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user