lcd-babel-plugin-immer-state 9.0.0-alpha.3 → 9.0.0-alpha.5
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/lib/index.d.ts +9 -8
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +40 -2
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export default function ({ t }: {
|
|
2
|
-
t: any;
|
|
3
|
-
}): {
|
|
4
|
-
name: string;
|
|
5
|
-
visitor: {
|
|
6
|
-
Identifier(path: any): void;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
1
|
+
export default function ({ t }: {
|
|
2
|
+
t: any;
|
|
3
|
+
}): {
|
|
4
|
+
name: string;
|
|
5
|
+
visitor: {
|
|
6
|
+
Identifier(path: any): void;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAU,EAAE,CAAC,EAAE;;CAAA;;;;;EAwC5B"}
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
function _default({
|
|
8
|
+
t
|
|
9
|
+
}) {
|
|
10
|
+
function find(properties, sourceName, propertiePath) {
|
|
11
|
+
for (let i = 0; i < properties.length; i++) {
|
|
12
|
+
const x = properties[i];
|
|
13
|
+
const valueName = x.get('value').node.name;
|
|
14
|
+
const keyName = x.get('key').node.name;
|
|
15
|
+
if ([valueName, keyName].includes(sourceName)) {
|
|
16
|
+
return `${propertiePath}.${keyName}`;
|
|
17
|
+
} else {
|
|
18
|
+
return find(x.get('value.properties'), sourceName, `${propertiePath}.${keyName}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
name: 'demo',
|
|
24
|
+
visitor: {
|
|
25
|
+
Identifier(path) {
|
|
26
|
+
if (path.isReferencedIdentifier() || path.findParent(path => path.isAssignmentExpression())) {
|
|
27
|
+
const binding = path.scope.getBinding(path.node.name);
|
|
28
|
+
if (binding) {
|
|
29
|
+
if (binding.path.get('init').isMemberExpression() && binding.path.get('init.property').node.name === 'state') {
|
|
30
|
+
const propertiesPath = binding.path.get('id.properties');
|
|
31
|
+
const r = find(propertiesPath, path.node.name, '');
|
|
32
|
+
path.node.name = 'this.state.' + r.substr(1, r.length);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../
|
|
1
|
+
{"version":3,"file":"index.js","names":["_default","t","find","properties","sourceName","propertiePath","i","length","x","valueName","get","node","name","keyName","includes","visitor","Identifier","path","isReferencedIdentifier","findParent","isAssignmentExpression","binding","scope","getBinding","isMemberExpression","propertiesPath","r","substr"],"sources":["../index.ts"],"sourcesContent":["export default function({ t }) {\n function find(properties, sourceName, propertiePath) {\n for (let i = 0; i < properties.length; i++) {\n const x = properties[i]\n const valueName = x.get('value').node.name\n const keyName = x.get('key').node.name\n if ([valueName, keyName].includes(sourceName)) {\n return `${propertiePath}.${keyName}`\n } else {\n return find(\n x.get('value.properties'),\n sourceName,\n `${propertiePath}.${keyName}`\n )\n }\n }\n }\n return {\n name: 'demo',\n visitor: {\n Identifier(path) {\n if (\n path.isReferencedIdentifier() ||\n path.findParent(path => path.isAssignmentExpression())\n ) {\n const binding = path.scope.getBinding(path.node.name)\n if (binding) {\n if (\n binding.path.get('init').isMemberExpression() &&\n binding.path.get('init.property').node.name === 'state'\n ) {\n const propertiesPath = binding.path.get('id.properties')\n const r = find(propertiesPath, path.node.name, '')\n path.node.name = 'this.state.' + r.substr(1, r.length)\n }\n }\n }\n },\n },\n }\n}\n"],"mappings":";;;;;;AAAe,SAAAA,SAAS;EAAEC;AAAE,CAAC,EAAE;EAC7B,SAASC,IAAIA,CAACC,UAAU,EAAEC,UAAU,EAAEC,aAAa,EAAE;IACnD,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,UAAU,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;MAC1C,MAAME,CAAC,GAAGL,UAAU,CAACG,CAAC,CAAC;MACvB,MAAMG,SAAS,GAAGD,CAAC,CAACE,GAAG,CAAC,OAAO,CAAC,CAACC,IAAI,CAACC,IAAI;MAC1C,MAAMC,OAAO,GAAGL,CAAC,CAACE,GAAG,CAAC,KAAK,CAAC,CAACC,IAAI,CAACC,IAAI;MACtC,IAAI,CAACH,SAAS,EAAEI,OAAO,CAAC,CAACC,QAAQ,CAACV,UAAU,CAAC,EAAE;QAC7C,OAAQ,GAAEC,aAAc,IAAGQ,OAAQ,EAAC;MACtC,CAAC,MAAM;QACL,OAAOX,IAAI,CACTM,CAAC,CAACE,GAAG,CAAC,kBAAkB,CAAC,EACzBN,UAAU,EACT,GAAEC,aAAc,IAAGQ,OAAQ,EAAC,CAC9B;MACH;IACF;EACF;EACA,OAAO;IACLD,IAAI,EAAE,MAAM;IACZG,OAAO,EAAE;MACPC,UAAUA,CAACC,IAAI,EAAE;QACf,IACEA,IAAI,CAACC,sBAAsB,EAAE,IAC7BD,IAAI,CAACE,UAAU,CAACF,IAAI,IAAIA,IAAI,CAACG,sBAAsB,EAAE,CAAC,EACtD;UACA,MAAMC,OAAO,GAAGJ,IAAI,CAACK,KAAK,CAACC,UAAU,CAACN,IAAI,CAACN,IAAI,CAACC,IAAI,CAAC;UACrD,IAAIS,OAAO,EAAE;YACX,IACEA,OAAO,CAACJ,IAAI,CAACP,GAAG,CAAC,MAAM,CAAC,CAACc,kBAAkB,EAAE,IAC7CH,OAAO,CAACJ,IAAI,CAACP,GAAG,CAAC,eAAe,CAAC,CAACC,IAAI,CAACC,IAAI,KAAK,OAAO,EACvD;cACA,MAAMa,cAAc,GAAGJ,OAAO,CAACJ,IAAI,CAACP,GAAG,CAAC,eAAe,CAAC;cACxD,MAAMgB,CAAC,GAAGxB,IAAI,CAACuB,cAAc,EAAER,IAAI,CAACN,IAAI,CAACC,IAAI,EAAE,EAAE,CAAC;cAClDK,IAAI,CAACN,IAAI,CAACC,IAAI,GAAG,aAAa,GAAGc,CAAC,CAACC,MAAM,CAAC,CAAC,EAAED,CAAC,CAACnB,MAAM,CAAC;YACxD;UACF;QACF;MACF;IACF;EACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lcd-babel-plugin-immer-state",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.5",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "10015448 <519495771@qq.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"gitHead": "f34305f0d8a335e0953d3a5df8a32a8d5507a6f0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "
|
|
27
|
+
"build": "lecp",
|
|
28
28
|
"test": "jest",
|
|
29
29
|
"test:w": "jest --watch"
|
|
30
30
|
}
|