-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e243d7
commit 2625719
Showing
13 changed files
with
127 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { NodeTransform } from '../transform' | ||
import { findDir } from '../utils' | ||
import { | ||
createCallExpression, | ||
createFunctionExpression, | ||
createSimpleExpression, | ||
ExpressionNode, | ||
NodeTypes, | ||
PlainElementNode, | ||
SimpleExpressionNode | ||
} from '../ast' | ||
import { stringifyExpression } from './transformExpression' | ||
|
||
const seen = new WeakSet() | ||
const extractKeyValueRE = /(\w+)\s*:\s*"*(.*?)"*\s*[,}\n]/g | ||
|
||
export const transformScope: NodeTransform = (node, context) => { | ||
if (node.type === NodeTypes.ELEMENT) { | ||
const dir = findDir(node, 'scope') | ||
if (!dir || seen.has(node)) { | ||
return | ||
} | ||
seen.add(node) | ||
return () => { | ||
const codegenNode = | ||
node.codegenNode || | ||
(context.currentNode as PlainElementNode).codegenNode | ||
if (codegenNode && codegenNode.type === NodeTypes.VNODE_CALL) { | ||
node.codegenNode = createCallExpression( | ||
createFunctionExpression( | ||
transformScopeExpression(dir.exp!), | ||
codegenNode | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function transformScopeExpression( | ||
exp: string | ExpressionNode | ||
): ExpressionNode[] { | ||
const params: SimpleExpressionNode[] = [] | ||
const rExpString = stringifyExpression(exp) | ||
let match | ||
while ((match = extractKeyValueRE.exec(rExpString))) { | ||
params.push(createSimpleExpression(`${match[1]}=${match[2]}`)) | ||
} | ||
return params | ||
} | ||
|
||
export const trackVScopeScopes: NodeTransform = (node, context) => { | ||
if (node.type === NodeTypes.ELEMENT) { | ||
const vLet = findDir(node, 'scope') | ||
if (vLet) { | ||
const keys: string[] = [] | ||
let match | ||
while ((match = extractKeyValueRE.exec(vLet.exp!.loc.source))) { | ||
keys.push(match[1]) | ||
} | ||
if (!__BROWSER__ && context.prefixIdentifiers) { | ||
keys.forEach(context.addIdentifiers) | ||
} | ||
return () => { | ||
if (!__BROWSER__ && context.prefixIdentifiers) { | ||
keys.forEach(context.removeIdentifiers) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.