@jscutlery/playwright-ct-angular 0.2.2 → 0.4.0
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/README.md +37 -36
- package/hooks.esm.d.ts +1 -0
- package/index.cjs.js +39 -84
- package/index.esm.d.ts +1 -0
- package/index.esm.js +31 -82
- package/package.json +7 -1
- package/register-source.mjs +7 -6
- package/register.cjs.js +6 -5
- package/register.esm.d.ts +2 -0
- package/register.esm.js +6 -5
- package/src/index.d.ts +26 -19
- package/src/transform-angular.d.ts +29 -0
- package/transform-angular.cjs.d.ts +2 -0
- package/transform-angular.cjs.default.js +1 -0
- package/transform-angular.cjs.js +224 -0
- package/transform-angular.cjs.mjs +2 -0
- package/transform-angular.esm.d.ts +2 -0
- package/transform-angular.esm.js +218 -0
- package/src/lib/playwright-ct-angular.d.ts +0 -1062
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* Original file: https://github.com/microsoft/playwright/blob/8173cdc4857f8e0a98047e02e692c5da6544a170/packages/playwright-ct-core/src/tsxTransform.ts
|
|
17
|
+
*/
|
|
18
|
+
import { NodePath, types as t } from '@babel/core';
|
|
19
|
+
declare const _default: (api: object, options: Record<string, any>, dirname: string) => {
|
|
20
|
+
name: string;
|
|
21
|
+
visitor: {
|
|
22
|
+
Program: {
|
|
23
|
+
enter(this: import("@babel/core").PluginPass, path: NodePath<t.Program>): void;
|
|
24
|
+
exit(this: import("@babel/core").PluginPass, path: NodePath<t.Program>): void;
|
|
25
|
+
};
|
|
26
|
+
ImportDeclaration(this: import("@babel/core").PluginPass, p: NodePath<t.ImportDeclaration>): void;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./transform-angular.cjs.js').default;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var core = require('@babel/core');
|
|
5
|
+
var transform = require('playwright/lib/transform/transform');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
10
|
+
|
|
11
|
+
var lib = {};
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(lib, "__esModule", {
|
|
14
|
+
value: true
|
|
15
|
+
});
|
|
16
|
+
var declare_1 = lib.declare = declare;
|
|
17
|
+
lib.declarePreset = void 0;
|
|
18
|
+
const apiPolyfills = {
|
|
19
|
+
assertVersion: api => range => {
|
|
20
|
+
throwVersionError(range, api.version);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
{
|
|
24
|
+
Object.assign(apiPolyfills, {
|
|
25
|
+
targets: () => () => {
|
|
26
|
+
return {};
|
|
27
|
+
},
|
|
28
|
+
assumption: () => () => {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function declare(builder) {
|
|
34
|
+
return (api, options, dirname) => {
|
|
35
|
+
var _clonedApi2;
|
|
36
|
+
let clonedApi;
|
|
37
|
+
for (const name of Object.keys(apiPolyfills)) {
|
|
38
|
+
var _clonedApi;
|
|
39
|
+
if (api[name]) continue;
|
|
40
|
+
(_clonedApi = clonedApi) != null ? _clonedApi : clonedApi = copyApiObject(api);
|
|
41
|
+
clonedApi[name] = apiPolyfills[name](clonedApi);
|
|
42
|
+
}
|
|
43
|
+
return builder((_clonedApi2 = clonedApi) != null ? _clonedApi2 : api, options || {}, dirname);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
lib.declarePreset = declare;
|
|
47
|
+
function copyApiObject(api) {
|
|
48
|
+
let proto = null;
|
|
49
|
+
if (typeof api.version === "string" && /^7\./.test(api.version)) {
|
|
50
|
+
proto = Object.getPrototypeOf(api);
|
|
51
|
+
if (proto && (!hasOwnProperty.call(proto, "version") || !hasOwnProperty.call(proto, "transform") || !hasOwnProperty.call(proto, "template") || !hasOwnProperty.call(proto, "types"))) {
|
|
52
|
+
proto = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Object.assign({}, proto, api);
|
|
56
|
+
}
|
|
57
|
+
function throwVersionError(range, version) {
|
|
58
|
+
if (typeof range === "number") {
|
|
59
|
+
if (!Number.isInteger(range)) {
|
|
60
|
+
throw new Error("Expected string or integer value.");
|
|
61
|
+
}
|
|
62
|
+
range = `^${range}.0.0-0`;
|
|
63
|
+
}
|
|
64
|
+
if (typeof range !== "string") {
|
|
65
|
+
throw new Error("Expected string or integer value.");
|
|
66
|
+
}
|
|
67
|
+
const limit = Error.stackTraceLimit;
|
|
68
|
+
if (typeof limit === "number" && limit < 25) {
|
|
69
|
+
Error.stackTraceLimit = 25;
|
|
70
|
+
}
|
|
71
|
+
let err;
|
|
72
|
+
if (version.slice(0, 2) === "7.") {
|
|
73
|
+
err = new Error(`Requires Babel "^7.0.0-beta.41", but was loaded with "${version}". ` + `You'll need to update your @babel/core version.`);
|
|
74
|
+
} else {
|
|
75
|
+
err = new Error(`Requires Babel "${range}", but was loaded with "${version}". ` + `If you are sure you have a compatible version of @babel/core, ` + `it is likely that something in your build process is loading the ` + `wrong version. Inspect the stack trace of this error to look for ` + `the first entry that doesn't mention "@babel/core" or "babel-core" ` + `to see what is calling Babel.`);
|
|
76
|
+
}
|
|
77
|
+
if (typeof limit === "number") {
|
|
78
|
+
Error.stackTraceLimit = limit;
|
|
79
|
+
}
|
|
80
|
+
throw Object.assign(err, {
|
|
81
|
+
code: "BABEL_VERSION_UNSUPPORTED",
|
|
82
|
+
version,
|
|
83
|
+
range
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Copyright (c) Microsoft Corporation.
|
|
89
|
+
*
|
|
90
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
91
|
+
* you may not use this file except in compliance with the License.
|
|
92
|
+
* You may obtain a copy of the License at
|
|
93
|
+
*
|
|
94
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
95
|
+
*
|
|
96
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
97
|
+
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
98
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
99
|
+
* See the License for the specific language governing permissions and
|
|
100
|
+
* limitations under the License.
|
|
101
|
+
*
|
|
102
|
+
* Original file: https://github.com/microsoft/playwright/blob/8173cdc4857f8e0a98047e02e692c5da6544a170/packages/playwright-ct-core/src/tsxTransform.ts
|
|
103
|
+
*/
|
|
104
|
+
let classComponentNames;
|
|
105
|
+
let importInfos;
|
|
106
|
+
var transformAngular = declare_1((api) => {
|
|
107
|
+
api.assertVersion(7);
|
|
108
|
+
return {
|
|
109
|
+
name: 'jscutlery-playwright-angular-transform',
|
|
110
|
+
visitor: {
|
|
111
|
+
Program: {
|
|
112
|
+
enter(path) {
|
|
113
|
+
classComponentNames = collectClassMountUsages(path);
|
|
114
|
+
importInfos = new Map();
|
|
115
|
+
},
|
|
116
|
+
exit(path) {
|
|
117
|
+
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
+
let firstDeclaration;
|
|
119
|
+
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
let lastImportDeclaration;
|
|
121
|
+
path.get('body').forEach((p) => {
|
|
122
|
+
if (p.isImportDeclaration())
|
|
123
|
+
lastImportDeclaration = p;
|
|
124
|
+
else if (!firstDeclaration)
|
|
125
|
+
firstDeclaration = p;
|
|
126
|
+
});
|
|
127
|
+
const insertionPath = lastImportDeclaration || firstDeclaration;
|
|
128
|
+
if (!insertionPath)
|
|
129
|
+
return;
|
|
130
|
+
for (const [localName, componentImport] of [
|
|
131
|
+
...importInfos.entries(),
|
|
132
|
+
].reverse()) {
|
|
133
|
+
insertionPath.insertAfter(core.types.variableDeclaration('const', [
|
|
134
|
+
core.types.variableDeclarator(core.types.identifier(localName), core.types.objectExpression([
|
|
135
|
+
core.types.objectProperty(core.types.identifier('__pw_type'), core.types.stringLiteral('importRef')),
|
|
136
|
+
core.types.objectProperty(core.types.identifier('id'), core.types.stringLiteral(componentImport.id)),
|
|
137
|
+
])),
|
|
138
|
+
]));
|
|
139
|
+
}
|
|
140
|
+
transform.setTransformData('playwright-ct-core', [...importInfos.values()]);
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
ImportDeclaration(p) {
|
|
144
|
+
const importNode = p.node;
|
|
145
|
+
if (!core.types.isStringLiteral(importNode.source)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
// Convert JS imports that are used as components in JSX expressions into refs.
|
|
149
|
+
let importCount = 0;
|
|
150
|
+
for (const specifier of importNode.specifiers) {
|
|
151
|
+
if (core.types.isImportNamespaceSpecifier(specifier))
|
|
152
|
+
continue;
|
|
153
|
+
const { localName, info } = importInfo(importNode, specifier,
|
|
154
|
+
// @eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
155
|
+
this.filename);
|
|
156
|
+
if (classComponentNames.has(localName)) {
|
|
157
|
+
importInfos.set(localName, info);
|
|
158
|
+
++importCount;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// All the imports were from JSX => delete.
|
|
162
|
+
if (importCount && importCount === importNode.specifiers.length) {
|
|
163
|
+
p.skip();
|
|
164
|
+
p.remove();
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
function collectClassMountUsages(path) {
|
|
171
|
+
const names = new Set();
|
|
172
|
+
let isInMountCall = false;
|
|
173
|
+
path.traverse({
|
|
174
|
+
CallExpression: {
|
|
175
|
+
enter(p) {
|
|
176
|
+
if (core.types.isIdentifier(p.node.callee) && p.node.callee.name === 'mount') {
|
|
177
|
+
isInMountCall = true;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
/* Ignore any function or method calls in `mount` args.
|
|
181
|
+
* e.g. {inputs: {recipe: recipeMother.withBasicInfo()}}. */
|
|
182
|
+
if (isInMountCall) {
|
|
183
|
+
p.skip();
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
exit() {
|
|
187
|
+
isInMountCall = false;
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
Identifier(p) {
|
|
191
|
+
if (isInMountCall) {
|
|
192
|
+
names.add(p.node.name);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
return names;
|
|
197
|
+
}
|
|
198
|
+
function importInfo(importNode, specifier, filename) {
|
|
199
|
+
const importSource = importNode.source.value;
|
|
200
|
+
const idPrefix = path__default["default"]
|
|
201
|
+
.join(filename, '..', importSource)
|
|
202
|
+
.replace(/[^\w_\d]/g, '_');
|
|
203
|
+
const result = {
|
|
204
|
+
id: idPrefix,
|
|
205
|
+
filename,
|
|
206
|
+
importSource,
|
|
207
|
+
remoteName: undefined,
|
|
208
|
+
};
|
|
209
|
+
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
|
+
const imported = specifier.imported;
|
|
211
|
+
if (!core.types.isImportDefaultSpecifier(specifier)) {
|
|
212
|
+
if (core.types.isIdentifier(imported)) {
|
|
213
|
+
result.remoteName = imported.name;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
result.remoteName = imported.value;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (result.remoteName)
|
|
220
|
+
result.id += '_' + result.remoteName;
|
|
221
|
+
return { localName: specifier.local.name, info: result };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
module.exports = transformAngular;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import path__default from 'node:path';
|
|
2
|
+
import { types } from '@babel/core';
|
|
3
|
+
import { setTransformData } from 'playwright/lib/transform/transform';
|
|
4
|
+
|
|
5
|
+
var lib = {};
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(lib, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
var declare_1 = lib.declare = declare;
|
|
11
|
+
lib.declarePreset = void 0;
|
|
12
|
+
const apiPolyfills = {
|
|
13
|
+
assertVersion: api => range => {
|
|
14
|
+
throwVersionError(range, api.version);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
{
|
|
18
|
+
Object.assign(apiPolyfills, {
|
|
19
|
+
targets: () => () => {
|
|
20
|
+
return {};
|
|
21
|
+
},
|
|
22
|
+
assumption: () => () => {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function declare(builder) {
|
|
28
|
+
return (api, options, dirname) => {
|
|
29
|
+
var _clonedApi2;
|
|
30
|
+
let clonedApi;
|
|
31
|
+
for (const name of Object.keys(apiPolyfills)) {
|
|
32
|
+
var _clonedApi;
|
|
33
|
+
if (api[name]) continue;
|
|
34
|
+
(_clonedApi = clonedApi) != null ? _clonedApi : clonedApi = copyApiObject(api);
|
|
35
|
+
clonedApi[name] = apiPolyfills[name](clonedApi);
|
|
36
|
+
}
|
|
37
|
+
return builder((_clonedApi2 = clonedApi) != null ? _clonedApi2 : api, options || {}, dirname);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
lib.declarePreset = declare;
|
|
41
|
+
function copyApiObject(api) {
|
|
42
|
+
let proto = null;
|
|
43
|
+
if (typeof api.version === "string" && /^7\./.test(api.version)) {
|
|
44
|
+
proto = Object.getPrototypeOf(api);
|
|
45
|
+
if (proto && (!hasOwnProperty.call(proto, "version") || !hasOwnProperty.call(proto, "transform") || !hasOwnProperty.call(proto, "template") || !hasOwnProperty.call(proto, "types"))) {
|
|
46
|
+
proto = null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return Object.assign({}, proto, api);
|
|
50
|
+
}
|
|
51
|
+
function throwVersionError(range, version) {
|
|
52
|
+
if (typeof range === "number") {
|
|
53
|
+
if (!Number.isInteger(range)) {
|
|
54
|
+
throw new Error("Expected string or integer value.");
|
|
55
|
+
}
|
|
56
|
+
range = `^${range}.0.0-0`;
|
|
57
|
+
}
|
|
58
|
+
if (typeof range !== "string") {
|
|
59
|
+
throw new Error("Expected string or integer value.");
|
|
60
|
+
}
|
|
61
|
+
const limit = Error.stackTraceLimit;
|
|
62
|
+
if (typeof limit === "number" && limit < 25) {
|
|
63
|
+
Error.stackTraceLimit = 25;
|
|
64
|
+
}
|
|
65
|
+
let err;
|
|
66
|
+
if (version.slice(0, 2) === "7.") {
|
|
67
|
+
err = new Error(`Requires Babel "^7.0.0-beta.41", but was loaded with "${version}". ` + `You'll need to update your @babel/core version.`);
|
|
68
|
+
} else {
|
|
69
|
+
err = new Error(`Requires Babel "${range}", but was loaded with "${version}". ` + `If you are sure you have a compatible version of @babel/core, ` + `it is likely that something in your build process is loading the ` + `wrong version. Inspect the stack trace of this error to look for ` + `the first entry that doesn't mention "@babel/core" or "babel-core" ` + `to see what is calling Babel.`);
|
|
70
|
+
}
|
|
71
|
+
if (typeof limit === "number") {
|
|
72
|
+
Error.stackTraceLimit = limit;
|
|
73
|
+
}
|
|
74
|
+
throw Object.assign(err, {
|
|
75
|
+
code: "BABEL_VERSION_UNSUPPORTED",
|
|
76
|
+
version,
|
|
77
|
+
range
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Copyright (c) Microsoft Corporation.
|
|
83
|
+
*
|
|
84
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
85
|
+
* you may not use this file except in compliance with the License.
|
|
86
|
+
* You may obtain a copy of the License at
|
|
87
|
+
*
|
|
88
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
89
|
+
*
|
|
90
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
91
|
+
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
92
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
93
|
+
* See the License for the specific language governing permissions and
|
|
94
|
+
* limitations under the License.
|
|
95
|
+
*
|
|
96
|
+
* Original file: https://github.com/microsoft/playwright/blob/8173cdc4857f8e0a98047e02e692c5da6544a170/packages/playwright-ct-core/src/tsxTransform.ts
|
|
97
|
+
*/
|
|
98
|
+
let classComponentNames;
|
|
99
|
+
let importInfos;
|
|
100
|
+
var transformAngular = declare_1((api) => {
|
|
101
|
+
api.assertVersion(7);
|
|
102
|
+
return {
|
|
103
|
+
name: 'jscutlery-playwright-angular-transform',
|
|
104
|
+
visitor: {
|
|
105
|
+
Program: {
|
|
106
|
+
enter(path) {
|
|
107
|
+
classComponentNames = collectClassMountUsages(path);
|
|
108
|
+
importInfos = new Map();
|
|
109
|
+
},
|
|
110
|
+
exit(path) {
|
|
111
|
+
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
let firstDeclaration;
|
|
113
|
+
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
|
+
let lastImportDeclaration;
|
|
115
|
+
path.get('body').forEach((p) => {
|
|
116
|
+
if (p.isImportDeclaration())
|
|
117
|
+
lastImportDeclaration = p;
|
|
118
|
+
else if (!firstDeclaration)
|
|
119
|
+
firstDeclaration = p;
|
|
120
|
+
});
|
|
121
|
+
const insertionPath = lastImportDeclaration || firstDeclaration;
|
|
122
|
+
if (!insertionPath)
|
|
123
|
+
return;
|
|
124
|
+
for (const [localName, componentImport] of [
|
|
125
|
+
...importInfos.entries(),
|
|
126
|
+
].reverse()) {
|
|
127
|
+
insertionPath.insertAfter(types.variableDeclaration('const', [
|
|
128
|
+
types.variableDeclarator(types.identifier(localName), types.objectExpression([
|
|
129
|
+
types.objectProperty(types.identifier('__pw_type'), types.stringLiteral('importRef')),
|
|
130
|
+
types.objectProperty(types.identifier('id'), types.stringLiteral(componentImport.id)),
|
|
131
|
+
])),
|
|
132
|
+
]));
|
|
133
|
+
}
|
|
134
|
+
setTransformData('playwright-ct-core', [...importInfos.values()]);
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
ImportDeclaration(p) {
|
|
138
|
+
const importNode = p.node;
|
|
139
|
+
if (!types.isStringLiteral(importNode.source)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Convert JS imports that are used as components in JSX expressions into refs.
|
|
143
|
+
let importCount = 0;
|
|
144
|
+
for (const specifier of importNode.specifiers) {
|
|
145
|
+
if (types.isImportNamespaceSpecifier(specifier))
|
|
146
|
+
continue;
|
|
147
|
+
const { localName, info } = importInfo(importNode, specifier,
|
|
148
|
+
// @eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
149
|
+
this.filename);
|
|
150
|
+
if (classComponentNames.has(localName)) {
|
|
151
|
+
importInfos.set(localName, info);
|
|
152
|
+
++importCount;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// All the imports were from JSX => delete.
|
|
156
|
+
if (importCount && importCount === importNode.specifiers.length) {
|
|
157
|
+
p.skip();
|
|
158
|
+
p.remove();
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
function collectClassMountUsages(path) {
|
|
165
|
+
const names = new Set();
|
|
166
|
+
let isInMountCall = false;
|
|
167
|
+
path.traverse({
|
|
168
|
+
CallExpression: {
|
|
169
|
+
enter(p) {
|
|
170
|
+
if (types.isIdentifier(p.node.callee) && p.node.callee.name === 'mount') {
|
|
171
|
+
isInMountCall = true;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
/* Ignore any function or method calls in `mount` args.
|
|
175
|
+
* e.g. {inputs: {recipe: recipeMother.withBasicInfo()}}. */
|
|
176
|
+
if (isInMountCall) {
|
|
177
|
+
p.skip();
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
exit() {
|
|
181
|
+
isInMountCall = false;
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
Identifier(p) {
|
|
185
|
+
if (isInMountCall) {
|
|
186
|
+
names.add(p.node.name);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
return names;
|
|
191
|
+
}
|
|
192
|
+
function importInfo(importNode, specifier, filename) {
|
|
193
|
+
const importSource = importNode.source.value;
|
|
194
|
+
const idPrefix = path__default
|
|
195
|
+
.join(filename, '..', importSource)
|
|
196
|
+
.replace(/[^\w_\d]/g, '_');
|
|
197
|
+
const result = {
|
|
198
|
+
id: idPrefix,
|
|
199
|
+
filename,
|
|
200
|
+
importSource,
|
|
201
|
+
remoteName: undefined,
|
|
202
|
+
};
|
|
203
|
+
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
204
|
+
const imported = specifier.imported;
|
|
205
|
+
if (!types.isImportDefaultSpecifier(specifier)) {
|
|
206
|
+
if (types.isIdentifier(imported)) {
|
|
207
|
+
result.remoteName = imported.name;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
result.remoteName = imported.value;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (result.remoteName)
|
|
214
|
+
result.id += '_' + result.remoteName;
|
|
215
|
+
return { localName: specifier.local.name, info: result };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { transformAngular as default };
|