-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.js
36 lines (33 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
findDynamicAttributes,
isEventAttribute,
isTextNode,
isValueAttribute
} from '../utils'
import attributeExpression from './attribute'
import eventExpression from './event'
import textExpression from './text'
import valueExpression from './value'
export function createExpression(sourceNode, sourceFile, sourceCode, childNodeIndex) {
switch (true) {
case isTextNode(sourceNode):
return textExpression(sourceNode, sourceFile, sourceCode, childNodeIndex)
case isValueAttribute(sourceNode):
return valueExpression(sourceNode, sourceFile, sourceCode)
case isEventAttribute(sourceNode):
return eventExpression(sourceNode, sourceFile, sourceCode)
default:
return attributeExpression(sourceNode, sourceFile, sourceCode)
}
}
/**
* Create the attribute expressions
* @param {RiotParser.Node} sourceNode - any kind of node parsed via riot parser
* @param {string} sourceFile - source file path
* @param {string} sourceCode - original source
* @returns {Array} array containing all the attribute expressions
*/
export function createAttributeExpressions(sourceNode, sourceFile, sourceCode) {
return findDynamicAttributes(sourceNode)
.map(attribute => createExpression(attribute, sourceFile, sourceCode))
}