-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
39 lines (36 loc) · 906 Bytes
/
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
37
38
39
const resolveModule = require('./lib/resolveModule');
const processGlslTag = require('./lib/processGlslTag');
function transform() {
return {
name: 'glslify',
visitor: {
TaggedTemplateExpression(path, state) {
const { tag } = path.node;
if (
tag.type !== 'Identifier' ||
resolveModule(path, tag.name) !== 'glslify'
) {
return;
}
try {
processGlslTag(path, state);
} catch (e) {
throw path.buildCodeFrameError(e.message);
}
},
Program: {
exit(programPath) {
programPath.traverse({
ImportDeclaration(path) {
if (path.node.source.value === 'glslify') {
path.remove();
}
},
// TODO: remove requires
});
},
},
},
};
}
module.exports = transform;