Skip to content

Commit 5250b71

Browse files
committed
fix: ignore animation parsing errors
closes #152, #153
1 parent 81f16c6 commit 5250b71

File tree

3 files changed

+221
-255
lines changed

3 files changed

+221
-255
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
},
3535
"license": "MIT",
3636
"devDependencies": {
37-
"@nativescript/webpack": "^5.0.5",
38-
"postcss": "8.4.8",
39-
"tailwindcss": "^3.0.23"
37+
"@nativescript/webpack": "^5.0.8",
38+
"postcss": "8.4.16",
39+
"tailwindcss": "^3.1.8"
4040
},
4141
"dependencies": {
42-
"@hookun/parse-animation-shorthand": "^0.1.2"
42+
"@hookun/parse-animation-shorthand": "^0.1.4"
4343
},
4444
"peerDependencies": {
4545
"postcss": "^8.0.0"

src/expandAnimations.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
const { parseSingle, serialize } = require("@hookun/parse-animation-shorthand");
22

33
/**
4-
* @param {@} options
4+
* @param {@} options
55
* @returns {import('postcss').Plugin}
66
*/
77
module.exports = (options = { debug: false }) => {
88
return {
99
postcssPlugin: "postcss-nativescript-animations",
1010
Declaration(decl) {
11-
// replace animation: *
12-
// with animation-*:
13-
if (decl.prop === "animation") {
14-
const styles = parseSingle(decl.value);
15-
if (styles.duration && Number.isInteger(styles.duration)) {
16-
styles.duration = `${styles.duration / 1000}s`;
17-
}
18-
Object.entries(styles)
19-
.filter(([, value]) => typeof value === "object")
20-
.map(([key, value]) => [
21-
key,
22-
serialize({ [key]: value }).split(" ")[0],
23-
])
24-
.map(([key, value]) => (styles[key] = value));
11+
try {
12+
// replace animation: *
13+
// with animation-*:
14+
if (decl.prop === "animation") {
15+
const styles = parseSingle(decl.value);
16+
if (styles.duration && Number.isInteger(styles.duration)) {
17+
styles.duration = `${styles.duration / 1000}s`;
18+
}
19+
Object.entries(styles)
20+
.filter(([, value]) => typeof value === "object")
21+
.map(([key, value]) => [
22+
key,
23+
serialize({ [key]: value }).split(" ")[0],
24+
])
25+
.map(([key, value]) => (styles[key] = value));
2526

26-
Object.entries(styles)
27-
.filter(([, value]) => value !== "unset")
28-
.map(([key, value]) =>
29-
decl.parent.insertAfter(
30-
decl,
31-
decl.clone({
32-
prop: `animation-${camelToKebab(key)}`,
33-
value: `${value}`,
34-
})
35-
)
36-
);
27+
Object.entries(styles)
28+
.filter(([, value]) => value !== "unset")
29+
.map(([key, value]) =>
30+
decl.parent.insertAfter(
31+
decl,
32+
decl.clone({
33+
prop: `animation-${camelToKebab(key)}`,
34+
value: `${value}`,
35+
})
36+
)
37+
);
3738

38-
decl.remove();
39+
decl.remove();
40+
}
41+
} catch (err) {
42+
// ignore errors, and just keep the animation as-is
3943
}
4044
},
4145
};

0 commit comments

Comments
 (0)