-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.js
47 lines (43 loc) · 1.21 KB
/
babel.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
37
38
39
40
41
42
43
44
45
46
47
/**
* A visitor which removes a property, because that's Babel wants you to do it.
*/
const RemoveClassPropertyVisitor = {
ClassProperty(path) {
path.remove()
}
}
/**
* Convenience function for removing a property from the visited class.
*/
function removeProperty(path){
path.traverse(RemoveClassPropertyVisitor)
}
/**
* Returns the node's HTML as a string (as it is stored differently if the
* string uses quasi quotes instead of normal quotes)
*/
function getNodeHtmlString(node) {
const nodeValue = node.value
const type = nodeValue.type
if (type == 'TemplateLiteral') {
return nodeValue.quasis[0].value.raw
} else if (type == 'TaggedTemplateExpression') {
return nodeValue.quasi.quasis[0].value.raw
} else if (type == 'StringLiteral') {
return nodeValue.value
}
throw new Error(`HTML template value ${node.key.name} must be a TemplateLiteral\
TaggedTemplateExpression, or StringLiteral (found ${type}).`)
}
/**
* Returns the node's HTML as a string (as it is stored differently if the
* string uses quasi quotes instead of normal quotes)
*/
function getNodeObjectValue(node) {
return node.value
}
module.exports = {
getNodeHtmlString,
getNodeObjectValue,
removeProperty
}