Skip parsing inline JavaScript code in Less (#14109)

This commit is contained in:
fisker Cheung authored and GitHub committed 2023-01-30 13:31:23 +08:00
1 parent a26e8ace46
commit e01f86aa09
5 files changed
+79

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#### Keep inline JavaScript code as it is (#14109 by @fisker)
<!-- prettier-ignore -->
```less
// Input
.calcPxMixin() {
@functions: ~`(function() {
const designWidth = 3840
const actualWidth = 5760
this.calcPx = function(_) {
return _ * actualWidth / designWidth + 'px'
}
})()`;
}
// Prettier stable
.calcPxMixin() {
@functions: ~`(
function() {const designWidth = 3840 const actualWidth = 5760 this.calcPx =
function(_) {return _ * actualWidth / designWidth + "px"}}
)
() `;
}
// Prettier main
<Same as input>
```
+5
View File
@@ -203,6 +203,11 @@ async function parseNestedValue(node, options) {
}
async function parseValue(value, options) {
// Inline javascript in Less
if (options.parser === "less" && value.startsWith("~`")) {
return { type: "value-unknown", value };
}
const Parser = await import("postcss-values-parser/lib/parser.js").then(
(m) => m.default
);
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`inline-javascript.less format 1`] = `
====================================options=====================================
parsers: ["less"]
printWidth: 80
| printWidth
=====================================input======================================
// Deprecated feature https://lesscss.org/usage/#less-options-enable-inline-javascript-deprecated-
.calcPxMixin() {
@functions: ~\`(function() {
const designWidth = 3840
const actualWidth = 5760
this.calcPx = function(_) {
return _ * actualWidth / designWidth + 'px'
}
})()\`
}
=====================================output=====================================
// Deprecated feature https://lesscss.org/usage/#less-options-enable-inline-javascript-deprecated-
.calcPxMixin() {
@functions: ~\`(function() {
const designWidth = 3840
const actualWidth = 5760
this.calcPx = function(_) {
return _ * actualWidth / designWidth + 'px'
}
})()\`;
}
================================================================================
`;
@@ -0,0 +1,11 @@
// Deprecated feature https://lesscss.org/usage/#less-options-enable-inline-javascript-deprecated-
.calcPxMixin() {
@functions: ~`(function() {
const designWidth = 3840
const actualWidth = 5760
this.calcPx = function(_) {
return _ * actualWidth / designWidth + 'px'
}
})()`
}
@@ -0,0 +1 @@
run_spec(import.meta, ["less"]);