ember-scoped-css 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/babel-plugin-scoped-class.js +1 -49
- package/src/scopedClass.js +6 -0
package/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const appDependencyLoader = require('./src/app-dependency-loader');
|
|
|
9
9
|
const appScopedcssWebpack = require('./src/app-scopedcss-webpack');
|
|
10
10
|
const addonRewritecssRollup = require('./src/addon-rewritecss-rollup');
|
|
11
11
|
const babelPluginScopedClass = require('./src/babel-plugin-scoped-class');
|
|
12
|
+
const scopedClass = require('./src/scopedClass');
|
|
12
13
|
|
|
13
14
|
module.exports = {
|
|
14
15
|
rollupEmberTemplateImportsPlugin,
|
|
@@ -22,4 +23,5 @@ module.exports = {
|
|
|
22
23
|
appScopedcssWebpack,
|
|
23
24
|
addonRewritecssRollup,
|
|
24
25
|
babelPluginScopedClass,
|
|
26
|
+
'test-helper': { scopedClass },
|
|
25
27
|
};
|
package/package.json
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
const template = require('@babel/template').default;
|
|
2
2
|
const replaceScopedClass = require('./replaceScopedClass');
|
|
3
|
-
const nodePath = require('path');
|
|
4
|
-
const renameClass = require('./renameClass');
|
|
5
|
-
const getPostfix = require('./getPostfix');
|
|
6
3
|
|
|
7
|
-
const scopedClass = (
|
|
8
|
-
let scopedClassName = '';
|
|
4
|
+
const scopedClass = () => {
|
|
9
5
|
return {
|
|
10
6
|
visitor: {
|
|
11
|
-
ImportDeclaration(path) {
|
|
12
|
-
if (path.node.source.value === 'ember-scoped-css') {
|
|
13
|
-
// find import scopedClass
|
|
14
|
-
let sc = path.node.specifiers.find(
|
|
15
|
-
(s) => s.imported.name === 'scopedClass'
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
// store scopedClass local name
|
|
19
|
-
scopedClassName = sc.local.name;
|
|
20
|
-
|
|
21
|
-
// remove import scopedClass
|
|
22
|
-
if (path.node.specifiers.length === 1) {
|
|
23
|
-
path.remove();
|
|
24
|
-
} else {
|
|
25
|
-
path.node.specifiers = path.node.specifiers.filter((s) => s !== sc);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
|
|
30
7
|
CallExpression(path, state) {
|
|
31
8
|
if (path.node?.callee?.name === 'precompileTemplate') {
|
|
32
9
|
let source = '';
|
|
@@ -45,31 +22,6 @@ const scopedClass = (babel) => {
|
|
|
45
22
|
);
|
|
46
23
|
}
|
|
47
24
|
}
|
|
48
|
-
|
|
49
|
-
// scopedClass helper
|
|
50
|
-
if (
|
|
51
|
-
scopedClassName &&
|
|
52
|
-
path.node?.callee?.name === scopedClassName &&
|
|
53
|
-
path.node.arguments.length === 2 &&
|
|
54
|
-
path.node.arguments[0].type === 'StringLiteral' &&
|
|
55
|
-
path.node.arguments[1].type === 'StringLiteral'
|
|
56
|
-
) {
|
|
57
|
-
// get class name and css file path from scopedClass helper
|
|
58
|
-
let [className, relativeCssFilePath] = path.node.arguments.map(
|
|
59
|
-
(a) => a.value
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// rename class
|
|
63
|
-
let cssFilePath = nodePath.resolve(
|
|
64
|
-
nodePath.dirname(state.filename),
|
|
65
|
-
relativeCssFilePath
|
|
66
|
-
);
|
|
67
|
-
let postfix = getPostfix(cssFilePath);
|
|
68
|
-
let renamedClass = renameClass(className, postfix);
|
|
69
|
-
|
|
70
|
-
// replace scopedClass helper with renamed class
|
|
71
|
-
path.replaceWith(babel.types.stringLiteral(renamedClass));
|
|
72
|
-
}
|
|
73
25
|
},
|
|
74
26
|
},
|
|
75
27
|
};
|