mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-08-16 22:50:22 +03:00
Ensure we can call upgradeStyleSheet
without access to StyleManager
local functions
This commit is contained in:
parent
a4b0c63eaa
commit
8dd3ca738f
@ -147,58 +147,65 @@ describe('StyleManager', () => {
|
||||
// go looking for cached files, and will always use the css provided
|
||||
|
||||
it('does not upgrade already wrapped math', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: calc(10px/2); }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual("p { padding: calc(10px/2); }");
|
||||
});
|
||||
|
||||
it('does not upgrade negative numbers', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: 0 -1px; }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual("p { padding: 0 -1px; }");
|
||||
});
|
||||
|
||||
it('upgrades simple division', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: 10px/2; }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual("p { padding: calc(10px/2); }");
|
||||
});
|
||||
|
||||
it('upgrades multi parameter math', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: 0 10px/2 5em; }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual("p { padding: 0 calc(10px/2) 5em; }");
|
||||
});
|
||||
|
||||
it('upgrades math with spaces', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: 10px / 2; }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual("p { padding: calc(10px / 2); }");
|
||||
});
|
||||
|
||||
it('upgrades multiple math expressions in a single line', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: 10px/2 10px/3; }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual("p { padding: calc(10px/2) calc(10px/3); }");
|
||||
});
|
||||
|
||||
it('does not upgrade base64 strings', () => {
|
||||
// Regression Check
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { cursor: -webkit-image-set(url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAL0lEQVQoz2NgCD3x//9/BhBYBWdhgFVAiVW4JBFKGIa4AqD0//9D3pt4I4tAdAMAHTQ/j5Zom30AAAAASUVORK5CYII=')); }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual(
|
||||
"p { cursor: -webkit-image-set(url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAL0lEQVQoz2NgCD3x//9/BhBYBWdhgFVAiVW4JBFKGIa4AqD0//9D3pt4I4tAdAMAHTQ/j5Zom30AAAAASUVORK5CYII=')); }"
|
||||
@ -206,9 +213,10 @@ describe('StyleManager', () => {
|
||||
});
|
||||
|
||||
it('does not modify hsl function where `/` is valid', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { caret-color: hsl(228deg 4% 24% / 0.8); }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual(
|
||||
"p { caret-color: hsl(228deg 4% 24% / 0.8); }"
|
||||
@ -216,9 +224,10 @@ describe('StyleManager', () => {
|
||||
});
|
||||
|
||||
it('does not modify acos function, where math is valid', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { transform: rotate(acos(2 * 0.125)); }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual(
|
||||
"p { transform: rotate(acos(2 * 0.125)); }"
|
||||
@ -226,9 +235,10 @@ describe('StyleManager', () => {
|
||||
});
|
||||
|
||||
it('recognizes valid less variables: right side', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: @size + 12px; }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual(
|
||||
"p { padding: calc(@size + 12px); }"
|
||||
@ -236,9 +246,10 @@ describe('StyleManager', () => {
|
||||
});
|
||||
|
||||
it('recognizes valid less variables: left side', () => {
|
||||
let upgradedSheet = mathStyleManager.upgradeDeprecatedMathUsageForStyleSheet(
|
||||
let upgradedSheet = mathStyleManager.upgradeStyleSheet(
|
||||
"p { padding: 12px + @size; }",
|
||||
{}
|
||||
{},
|
||||
"math"
|
||||
);
|
||||
expect(upgradedSheet.source).toEqual(
|
||||
"p { padding: calc(12px + @size); }"
|
||||
|
@ -232,8 +232,20 @@ module.exports = class StyleManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper function useful for applying any upgrades due to deprecations
|
||||
upgradeStyleSheet(styleSheet, context, cb) {
|
||||
// Wrapper function useful for applying any upgrades due to deprecations
|
||||
upgradeStyleSheet(styleSheet, context, upgradeName) {
|
||||
let cb;
|
||||
|
||||
// Allows us to utilize a direct callback, or if calling from outside
|
||||
// StyleManager we can define a string that works
|
||||
if (upgradeName === "math") {
|
||||
cb = upgradeDeprecatedMathUsageForStyleSheet;
|
||||
} else if (upgradeName === "selector") {
|
||||
cb = transformDeprecatedShadowDOMSelectors;
|
||||
} else if (typeof upgradeName === "function") {
|
||||
cb = upgradeName;
|
||||
}
|
||||
|
||||
if (this.cacheDirPath != null) {
|
||||
const hash = crypto.createHash("sha1");
|
||||
if (context != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user