Socket
Socket
Sign inDemoInstall

postcss-styled-syntax

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-styled-syntax - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

68

lib/parseJs.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc