Skip to content

Commit 5675ecc

Browse files
committed
test(transformer): fix merging options in fixtures update script
1 parent ccfeb68 commit 5675ecc

2 files changed

Lines changed: 3 additions & 61 deletions

File tree

tasks/transform_conformance/snapshots/babel.snap.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
commit: 54a8389f
22

3-
Passed: 437/846
3+
Passed: 439/846
44

55
# All Passed:
66
* babel-plugin-transform-class-static-block
@@ -276,7 +276,7 @@ x Output mismatch
276276
x Output mismatch
277277

278278

279-
# babel-plugin-transform-class-properties (110/264)
279+
# babel-plugin-transform-class-properties (112/264)
280280
* assumption-constantSuper/complex-super-class/input.js
281281
x Output mismatch
282282

@@ -795,9 +795,6 @@ x Output mismatch
795795
* private-loose/update/input.js
796796
x Output mismatch
797797

798-
* public/arrow-static-this-without-transform/input.js
799-
x Output mismatch
800-
801798
* public/call/input.js
802799
Scope children mismatch:
803800
after transform: ScopeId(1): [ScopeId(2), ScopeId(3), ScopeId(4)]
@@ -901,9 +898,6 @@ rebuilt : ScopeId(2): Some(ScopeId(0))
901898
* public/super-with-collision/input.js
902899
x Output mismatch
903900

904-
* public-loose/arrow-static-this-without-transform/input.js
905-
x Output mismatch
906-
907901
* public-loose/class-shadow-builtins/input.mjs
908902
x Output mismatch
909903

tasks/transform_conformance/update_fixtures.js

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async function updateDir(dirPath, options, hasChangedOptions) {
110110
await backupFile(path);
111111
await writeFile(path, JSON.stringify(localOptions, null, 2) + '\n');
112112
}
113-
options = mergeOptions(options, localOptions);
113+
options = { ...options, ...localOptions };
114114
}
115115

116116
// Run Babel with updated options/input
@@ -154,58 +154,6 @@ function updateOptions(options) {
154154
return hasChangedOptions;
155155
}
156156

157-
/**
158-
* Merge `options` into `parentOptions`.
159-
* Returns merged options object. Does not mutate either input.
160-
* @param {Object} parentOptions - Parent options
161-
* @param {Object} options - Local options
162-
* @returns {Object} - Merged options object
163-
*/
164-
function mergeOptions(parentOptions, options) {
165-
parentOptions = { ...parentOptions };
166-
167-
function merge(key) {
168-
if (!options[key]) return;
169-
170-
if (!parentOptions[key]) {
171-
parentOptions[key] = options[key];
172-
return;
173-
}
174-
175-
parentOptions[key] = [...parentOptions[key]];
176-
177-
const parentPluginIndexes = new Map();
178-
for (const [index, plugin] of parentOptions[key].entries()) {
179-
parentPluginIndexes.set(getName(plugin), index);
180-
}
181-
182-
for (const plugin of options[key]) {
183-
const pluginName = getName(plugin);
184-
const parentPluginIndex = parentPluginIndexes.get(pluginName);
185-
if (parentPluginIndex !== undefined) {
186-
parentOptions[key][parentPluginIndex] = plugin;
187-
} else {
188-
parentOptions[key].push(plugin);
189-
}
190-
}
191-
}
192-
193-
merge('presets');
194-
merge('plugins');
195-
196-
if (options.assumptions) {
197-
parentOptions.assumptions = { ...parentOptions.assumptions, ...options.assumptions };
198-
}
199-
200-
for (const [key, value] of Object.entries(options)) {
201-
if (key === 'plugins' || key === 'presets' || key === 'assumptions') continue;
202-
if (Object.hasOwn(parentOptions, key)) throw new Error(`Clash: ${key}`);
203-
parentOptions[key] = value;
204-
}
205-
206-
return parentOptions;
207-
}
208-
209157
/**
210158
* Transform input with Babel and save to output file.
211159
* @param {string} inputPath - Path of input file

0 commit comments

Comments
 (0)