postcss-styled-syntax
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -16,37 +16,38 @@ let ts = require('typescript'); | ||
let sourceFile = ts.createSourceFile( | ||
opts?.from || 'unnamed.ts', | ||
inputCode, | ||
ts.ScriptTarget.Latest, | ||
// true, | ||
// ts.ScriptKind.TSX, | ||
); | ||
try { | ||
let sourceFile = ts.createSourceFile( | ||
opts?.from || 'unnamed.ts', | ||
inputCode, | ||
ts.ScriptTarget.Latest, | ||
// true, | ||
// ts.ScriptKind.TSX, | ||
); | ||
/** | ||
* Recursively visits the nodes in the AST | ||
* | ||
* @param {ts.Node} node - The current node in the AST. | ||
*/ | ||
function visit(node) { | ||
// Check if the node is a TaggedTemplateExpression | ||
if (ts.isTaggedTemplateExpression(node) && isStyledComponent(node)) { | ||
let nodeCssData = getNodeCssData(node, inputCode, sourceFile); | ||
/** | ||
* Recursively visits the nodes in the AST | ||
* | ||
* @param {ts.Node} node - The current node in the AST. | ||
*/ | ||
// eslint-disable-next-line no-inner-declarations | ||
function visit(node) { | ||
// Check if the node is a TaggedTemplateExpression | ||
if (ts.isTaggedTemplateExpression(node) && isStyledComponent(node)) { | ||
let nodeCssData = getNodeCssData(node, inputCode, sourceFile); | ||
foundNodes.push(nodeCssData); | ||
foundNodes.push(nodeCssData); | ||
} | ||
// Continue recursion down the tree | ||
ts.forEachChild(node, visit); | ||
} | ||
// Continue recursion down the tree | ||
ts.forEachChild(node, visit); | ||
} | ||
// @ts-expect-error -- parseDiagnostics is not public API. However, TS is crashing or very-very slow if using official way | ||
// https://github.com/microsoft/TypeScript/issues/21940 | ||
let hasParseErrors = sourceFile.parseDiagnostics?.length > 0; | ||
// @ts-expect-error -- parseDiagnostics is not public API. However, TS is crashing or very-very slow if using official way | ||
// https://github.com/microsoft/TypeScript/issues/21940 | ||
let hasParseErrors = sourceFile.parseDiagnostics?.length > 0; | ||
if (!hasParseErrors) { | ||
try { | ||
if (!hasParseErrors) { | ||
visit(sourceFile); | ||
} catch (error) { | ||
// Don't show parsing errors for JavaScript/TypeScript, because they are not relevant to CSS. And these errors most likely caught for user by JavaScript tools already | ||
} | ||
} catch (error) { | ||
// Don't show parsing errors for JavaScript/TypeScript, because they are not relevant to CSS. And these errors most likely caught for user by JavaScript tools already | ||
} | ||
@@ -73,6 +74,13 @@ | ||
// To include `${` | ||
let start = templateSpan.expression.pos - 2; | ||
let start = templateSpan.pos - 2; | ||
// To include `}` | ||
let end = templateSpan.expression.end + 1; | ||
let end = templateSpan.literal.end - templateSpan.literal.text.length; | ||
if (ts.isTemplateTail(templateSpan.literal)) { | ||
end = end - 1; | ||
} else { | ||
// If it's a TemplateMiddle | ||
end = end - 2; | ||
} | ||
interpolationRanges.push({ start, end }); | ||
@@ -79,0 +87,0 @@ } |
{ | ||
"name": "postcss-styled-syntax", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "PostCSS syntax for template literals CSS-in-JS (e. g. styled-components).", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36495
1055