@stylable/code-formatter
Advanced tools
Comparing version 4.9.4 to 4.9.5
@@ -18,14 +18,22 @@ "use strict"; | ||
function removeFormattingExceptions(ast) { | ||
const changes = []; | ||
const atRuleChanges = []; | ||
const declChanges = []; | ||
// sanitizing @st-imports due to resulting broken formatting | ||
ast.walkAtRules(stImport, (atRule) => { | ||
changes.push(atRule.params); | ||
atRuleChanges.push(atRule.params); | ||
atRule.params = 'temp'; | ||
}); | ||
return changes; | ||
ast.walkDecls(/^grid/, (decl) => { | ||
declChanges.push(decl.value); | ||
decl.value = `temp`; | ||
}); | ||
return { atRuleChanges, declChanges }; | ||
} | ||
function restoreFormattingExceptions(ast, changes) { | ||
function restoreFormattingExceptions(ast, { atRuleChanges, declChanges }) { | ||
ast.walkAtRules(stImport, (atRule) => { | ||
atRule.params = changes.shift(); | ||
atRule.params = atRuleChanges.shift(); | ||
}); | ||
ast.walkDecls(/^grid/, (decl) => { | ||
decl.value = declChanges.shift(); | ||
}); | ||
return ast; | ||
@@ -32,0 +40,0 @@ } |
{ | ||
"name": "@stylable/code-formatter", | ||
"version": "4.9.4", | ||
"version": "4.9.5", | ||
"description": "A code formatting utility for Stylable stylesheets", | ||
@@ -10,3 +10,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@stylable/core": "^4.9.4", | ||
"@stylable/core": "^4.9.5", | ||
"js-beautify": "^1.14.0" | ||
@@ -13,0 +13,0 @@ }, |
@@ -26,18 +26,31 @@ import { safeParse } from '@stylable/core'; | ||
function removeFormattingExceptions(ast: Root) { | ||
const changes: string[] = []; | ||
const atRuleChanges: string[] = []; | ||
const declChanges: string[] = []; | ||
// sanitizing @st-imports due to resulting broken formatting | ||
ast.walkAtRules(stImport, (atRule) => { | ||
changes.push(atRule.params); | ||
atRuleChanges.push(atRule.params); | ||
atRule.params = 'temp'; | ||
}); | ||
return changes; | ||
ast.walkDecls(/^grid/, (decl) => { | ||
declChanges.push(decl.value); | ||
decl.value = `temp`; | ||
}); | ||
return { atRuleChanges, declChanges }; | ||
} | ||
function restoreFormattingExceptions(ast: Root, changes: string[]) { | ||
function restoreFormattingExceptions( | ||
ast: Root, | ||
{ atRuleChanges, declChanges }: { atRuleChanges: string[]; declChanges: string[] } | ||
) { | ||
ast.walkAtRules(stImport, (atRule) => { | ||
atRule.params = changes.shift()!; | ||
atRule.params = atRuleChanges.shift()!; | ||
}); | ||
ast.walkDecls(/^grid/, (decl) => { | ||
decl.value = declChanges.shift()!; | ||
}); | ||
return ast; | ||
@@ -44,0 +57,0 @@ } |
Sorry, the diff of this file is not supported yet
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
8912
110
Updated@stylable/core@^4.9.5