Skip to content

Instantly share code, notes, and snippets.

@longlho
Last active August 20, 2019 02:38
Show Gist options
  • Save longlho/b39473d8e415fc8a1e77b1ddd3a04c33 to your computer and use it in GitHub Desktop.
Save longlho/b39473d8e415fc8a1e77b1ddd3a04c33 to your computer and use it in GitHub Desktop.
transformer-p5.ts
if (ts.isImportDeclaration(node)) {
// Handle `import foo.css`
if (CSS_EXTENSION_REGEX.test(node.moduleSpecifier.getText())) {
cssPath = resolveCssPath(
node.moduleSpecifier.getText(),
sf,
tsImportResolver
);
newNode = importVisitor(cssPath, node);
}
} else if (
// Handle `require('foo.css')`
ts.isCallExpression(node) &&
node.expression.getText() === "require" &&
CSS_EXTENSION_REGEX.test(node.arguments[0].getText())
) {
cssPath = resolveCssPath(
node.arguments[0].getText(),
sf,
tsImportResolver
);
try {
newNode = generateClassNameObj(cssPath);
} catch (e) {
console.error(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment