-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmacro.js
More file actions
25 lines (22 loc) · 735 Bytes
/
macro.js
File metadata and controls
25 lines (22 loc) · 735 Bytes
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
const { createMacro, MacroError } = require('babel-plugin-macros');
const processGlslTag = require('./lib/processGlslTag');
function glslifyMacro({ references, state, babel }) {
const t = babel.types;
const { default: defaultImport = [] } = references;
defaultImport.forEach(referencePath => {
const path = referencePath.parentPath;
if (
(t.isCallExpression(path.node) &&
t.isStringLiteral(path.node.arguments[0])) ||
t.isTaggedTemplateExpression(path.node)) {
try {
processGlslTag(path, state);
} catch (e) {
throw new MacroError(e.message);
}
} else {
throw new MacroError(`${referencePath}`);
}
});
}
module.exports = createMacro(glslifyMacro);