Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dist/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const parse = (source, opts) => {
const { from } = opts;
logger_1.logger.info(`Parsing ${from}`);
const document = (0, postcss_1.parse)("", { from });
// Store the original TypeScript source so the stringifier can return it
// unchanged when there are no inline styles to process.
document.raws.angularSource = sourceString;
try {
const allStyles = (0, get_component_metadata_1.getComponentStyles)(sourceString, from);
logger_1.logger.info(`Located ${allStyles.length} inline styles.`);
Expand Down
11 changes: 10 additions & 1 deletion dist/stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ const logger_1 = require("./logger");
const stringify = (node, builder) => {
logger_1.logger.info(`Stringify called.`);
try {
node.root().nodes.forEach((node) => {
const root = node.root();
const nodes = root.nodes;
if (nodes.length === 0) {
// No inline styles — return the original TypeScript source unchanged
// to prevent stylelint's fix mode from writing an empty string back
// to disk.
builder(root.raws.angularSource ?? "");
return;
}
nodes.forEach((node) => {
builder(node.raws.angularCodeBefore, node);
(0, postcss_1.stringify)(node, builder);
builder(node.raws.angularCodeAfter, node);
Expand Down
6 changes: 5 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProcessOptions, Root, parse as postcssParse, Document } from "postcss";
import { ProcessOptions, Root, parse as postcssParse } from "postcss";
import { getComponentStyles } from "./get-component-metadata";
import { logger } from "./logger";

Expand All @@ -10,6 +10,10 @@ export const parse = (source: string, opts: ProcessOptions): Root => {

const document = postcssParse("", { from });

// Store the original TypeScript source so the stringifier can return it
// unchanged when there are no inline styles to process.
document.raws.angularSource = sourceString;

try {
const allStyles = getComponentStyles(sourceString, from);

Expand Down
12 changes: 11 additions & 1 deletion src/stringifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ export const stringify = (node: AnyNode, builder) => {
logger.info(`Stringify called.`);

try {
node.root().nodes.forEach((node) => {
const root = node.root();
const nodes = root.nodes;

if (nodes.length === 0) {
// No inline styles — return the original TypeScript source unchanged to
// prevent stylelint's fix mode from writing an empty string back to disk.
builder(root.raws.angularSource ?? "");
return;
}

nodes.forEach((node) => {
builder(node.raws.angularCodeBefore, node);
postcssStringify(node, builder);
builder(node.raws.angularCodeAfter, node);
Expand Down