@cssxjs/babel-plugin-rn-stylename-to-style 0.2.13 → 0.2.15
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/CHANGELOG.md +24 -0
- package/index.js +45 -36
- package/package.json +5 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
# v0.2.15 (Sun Nov 09 2025)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- fix(babel-plugin-rn-stylename-to-style): remove teamplay from peer deps ([@cray0000](https://github.com/cray0000))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# v0.2.14 (Sat Nov 08 2025)
|
|
14
|
+
|
|
15
|
+
#### 🐛 Bug Fix
|
|
16
|
+
|
|
17
|
+
- fix(babel-plugin-rn-stylename-to-style): add a workaround for adding runtime - use named export for it ([@cray0000](https://github.com/cray0000))
|
|
18
|
+
|
|
19
|
+
#### Authors: 1
|
|
20
|
+
|
|
21
|
+
- Pavel Zhukov ([@cray0000](https://github.com/cray0000))
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
1
25
|
# v0.2.13 (Sat Nov 08 2025)
|
|
2
26
|
|
|
3
27
|
#### 🐛 Bug Fix
|
package/index.js
CHANGED
|
@@ -2,13 +2,15 @@ const nodePath = require('path')
|
|
|
2
2
|
const t = require('@babel/types')
|
|
3
3
|
const template = require('@babel/template').default
|
|
4
4
|
const { GLOBAL_NAME, LOCAL_NAME } = require('@cssxjs/runtime/constants')
|
|
5
|
+
const { addNamed } = require('@babel/helper-module-imports')
|
|
5
6
|
|
|
6
7
|
const COMPILERS = ['css', 'styl', 'pug'] // used in rn-stylename-inline. TODO: move to a shared place
|
|
7
8
|
const RUNTIME_LIBRARY = 'cssxjs/runtime'
|
|
8
9
|
const STYLE_NAME_REGEX = /(?:^s|S)tyleName$/
|
|
9
10
|
const STYLE_REGEX = /(?:^s|S)tyle$/
|
|
10
11
|
const ROOT_STYLE_PROP_NAME = 'style'
|
|
11
|
-
const
|
|
12
|
+
const RUNTIME_IMPORT_NAME = 'runtime'
|
|
13
|
+
const RUNTIME_FRIENDLY_NAME = 'cssx'
|
|
12
14
|
const OPTIONS_CACHE = ['teamplay']
|
|
13
15
|
const OPTIONS_REACT_TYPES = ['react-native', 'web']
|
|
14
16
|
const DEFAULT_MAGIC_IMPORTS = ['cssxjs', 'startupjs']
|
|
@@ -19,30 +21,52 @@ const buildSafeVar = template.expression(`
|
|
|
19
21
|
typeof %%variable%% !== 'undefined' && %%variable%%
|
|
20
22
|
`)
|
|
21
23
|
|
|
22
|
-
const buildImport = template(`
|
|
23
|
-
import %%name%% from %%runtimePath%%
|
|
24
|
-
`)
|
|
25
|
-
|
|
26
|
-
const buildRequire = template(`
|
|
27
|
-
const %%name%% = require(%%runtimePath%%)
|
|
28
|
-
`)
|
|
29
|
-
|
|
30
24
|
const buildJsonParse = template(`
|
|
31
25
|
const %%name%% = JSON.parse(%%jsonStyle%%)
|
|
32
26
|
`)
|
|
33
27
|
|
|
28
|
+
const buildRuntimeVar = template(`
|
|
29
|
+
const %%name%% = %%imported%%
|
|
30
|
+
`)
|
|
31
|
+
|
|
34
32
|
module.exports = function (babel) {
|
|
35
33
|
let styleHash = {}
|
|
36
34
|
let cssIdentifier
|
|
37
35
|
let hasObserver
|
|
38
36
|
let $program
|
|
39
37
|
let usedCompilers
|
|
38
|
+
let runtime
|
|
39
|
+
|
|
40
|
+
function getOrCreateRuntime (state) {
|
|
41
|
+
if (runtime) return runtime
|
|
42
|
+
const runtimePath = getRuntimePath($program, state, hasObserver)
|
|
43
|
+
// when using addDefault for some reason Expo doesn't keep the imported variable correctly,
|
|
44
|
+
// because of this we hack it by importing first and then assigning to a const with the final name
|
|
45
|
+
// used later in the code to call the runtime function.
|
|
46
|
+
const imported = addNamedImport($program, RUNTIME_IMPORT_NAME, runtimePath)
|
|
47
|
+
runtime = $program.scope.generateUidIdentifier(RUNTIME_FRIENDLY_NAME)
|
|
48
|
+
|
|
49
|
+
const expression = buildRuntimeVar({
|
|
50
|
+
name: runtime,
|
|
51
|
+
imported
|
|
52
|
+
})
|
|
53
|
+
const lastImport = $program
|
|
54
|
+
.get('body')
|
|
55
|
+
.filter(p => p.isImportDeclaration())
|
|
56
|
+
.pop()
|
|
57
|
+
if (lastImport) {
|
|
58
|
+
lastImport.insertAfter(expression)
|
|
59
|
+
} else {
|
|
60
|
+
$program.unshiftContainer('body', expression)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return runtime
|
|
64
|
+
}
|
|
40
65
|
|
|
41
66
|
function getStyleFromExpression (expression, state) {
|
|
42
|
-
state.hasTransformedClassName = true
|
|
43
67
|
const cssStyles = cssIdentifier.name
|
|
44
68
|
const processCall = t.callExpression(
|
|
45
|
-
state
|
|
69
|
+
getOrCreateRuntime(state),
|
|
46
70
|
[expression, t.identifier(cssStyles)]
|
|
47
71
|
)
|
|
48
72
|
return processCall
|
|
@@ -153,9 +177,8 @@ module.exports = function (babel) {
|
|
|
153
177
|
}
|
|
154
178
|
|
|
155
179
|
// Create a `process` function call
|
|
156
|
-
state.hasTransformedClassName = true
|
|
157
180
|
const processCall = t.callExpression(
|
|
158
|
-
state
|
|
181
|
+
getOrCreateRuntime(state),
|
|
159
182
|
[
|
|
160
183
|
styleName
|
|
161
184
|
? (
|
|
@@ -246,6 +269,7 @@ module.exports = function (babel) {
|
|
|
246
269
|
hasObserver = undefined
|
|
247
270
|
$program = undefined
|
|
248
271
|
usedCompilers = undefined
|
|
272
|
+
runtime = undefined
|
|
249
273
|
},
|
|
250
274
|
visitor: {
|
|
251
275
|
Program: {
|
|
@@ -253,7 +277,6 @@ module.exports = function (babel) {
|
|
|
253
277
|
enter ($this, state) {
|
|
254
278
|
// 1. Init
|
|
255
279
|
usedCompilers = getUsedCompilers($this, state)
|
|
256
|
-
state.reqName = $this.scope.generateUidIdentifier(RUNTIME_PROCESS_NAME)
|
|
257
280
|
$program = $this
|
|
258
281
|
|
|
259
282
|
// 2. Run early traversal of everything
|
|
@@ -364,9 +387,8 @@ module.exports = function (babel) {
|
|
|
364
387
|
if (!$callee.isIdentifier()) return
|
|
365
388
|
if (!usedCompilers.has($callee.node.name)) return
|
|
366
389
|
// Create a `process` function call
|
|
367
|
-
state.hasTransformedClassName = true
|
|
368
390
|
const processCall = t.callExpression(
|
|
369
|
-
state
|
|
391
|
+
getOrCreateRuntime(state),
|
|
370
392
|
[
|
|
371
393
|
$this.get('arguments.0')
|
|
372
394
|
? $this.get('arguments.0').node
|
|
@@ -384,26 +406,6 @@ module.exports = function (babel) {
|
|
|
384
406
|
$this.replaceWith(processCall)
|
|
385
407
|
}
|
|
386
408
|
}, state)
|
|
387
|
-
|
|
388
|
-
// 3. Finalize
|
|
389
|
-
if (!state.hasTransformedClassName) {
|
|
390
|
-
return
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const lastImportOrRequire = $this
|
|
394
|
-
.get('body')
|
|
395
|
-
.filter(p => p.isImportDeclaration() || isRequire(p.node))
|
|
396
|
-
.pop()
|
|
397
|
-
|
|
398
|
-
if (lastImportOrRequire) {
|
|
399
|
-
const useImport = state.opts.useImport == null ? true : state.opts.useImport
|
|
400
|
-
const runtimePath = getRuntimePath($this, state, hasObserver)
|
|
401
|
-
lastImportOrRequire.insertAfter(
|
|
402
|
-
useImport
|
|
403
|
-
? buildImport({ name: state.reqName, runtimePath: t.stringLiteral(runtimePath) })
|
|
404
|
-
: buildRequire({ name: state.reqName, runtimePath: t.stringLiteral(runtimePath) })
|
|
405
|
-
)
|
|
406
|
-
}
|
|
407
409
|
}
|
|
408
410
|
}
|
|
409
411
|
}
|
|
@@ -582,3 +584,10 @@ function getRuntimePath ($node, state, hasObserver) {
|
|
|
582
584
|
}
|
|
583
585
|
return runtimePath
|
|
584
586
|
}
|
|
587
|
+
|
|
588
|
+
function addNamedImport ($program, name, sourceName) {
|
|
589
|
+
return addNamed($program, name, sourceName, {
|
|
590
|
+
importedType: 'es6',
|
|
591
|
+
importPosition: 'after'
|
|
592
|
+
})
|
|
593
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssxjs/babel-plugin-rn-stylename-to-style",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -23,18 +23,16 @@
|
|
|
23
23
|
"url": "https://github.com/startupjs/startupjs"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@babel/helper-module-imports": "^7.0.0",
|
|
26
27
|
"@babel/template": "^7.4.0",
|
|
27
28
|
"@babel/types": "^7.0.0",
|
|
28
|
-
"@cssxjs/runtime": "^0.2.
|
|
29
|
+
"@cssxjs/runtime": "^0.2.15"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@babel/plugin-syntax-jsx": "^7.0.0",
|
|
32
|
-
"@cssxjs/babel-plugin-react-pug": "^0.2.
|
|
33
|
+
"@cssxjs/babel-plugin-react-pug": "^0.2.15",
|
|
33
34
|
"babel-plugin-tester": "^9.1.0",
|
|
34
35
|
"jest": "^30.0.4"
|
|
35
36
|
},
|
|
36
|
-
"
|
|
37
|
-
"teamplay": "*"
|
|
38
|
-
},
|
|
39
|
-
"gitHead": "a560e6b7ed6c0c1725b8b9c2bf241d28a6ce2617"
|
|
37
|
+
"gitHead": "3ab2ccbdfdd935546be993322c645f216e4768e3"
|
|
40
38
|
}
|