Skip to content

Commit 1f3e9ef

Browse files
committed
wip
1 parent 1621df6 commit 1f3e9ef

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

.github/workflows/tests-base.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,22 @@ jobs:
3636
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
3737
coverage: none
3838

39-
- name: Install Dependencies
39+
- name: Install PHP Dependencies
4040
run: |
4141
composer self-update
4242
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
4343
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
4444
45-
- name: Run Tests
45+
- name: Setup Node.js
46+
uses: actions/setup-node@v3
47+
with:
48+
node-version: '20'
49+
50+
- name: Install Node Dependencies
51+
run: npm install
52+
53+
- name: Run npm tests
54+
run: npm run test
55+
56+
- name: Run PHP Tests
4657
run: vendor/bin/phpunit

packages/vue/injectors/modifyScriptSetup.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function injector(code, script, keys) {
66
}
77

88
function rewrite(code, script, keys) {
9-
// Throw error if useFusion is imported with an alias
9+
// Throw an error if useFusion is imported with an alias.
1010
checkAliasedUseFusion(script.content);
1111

1212
const originalContent = script.content;
@@ -18,13 +18,13 @@ function rewrite(code, script, keys) {
1818
throw new Error("Multiple useFusion calls are not allowed.");
1919
}
2020

21-
// Check if the user has any useFusion call in their code.
21+
// Check if the user has any useFusion call.
2222
const hasUserCall = /useFusion\s*\(/.test(userCode);
2323
let rewritten = "";
2424
let remainingKeys = keys.slice();
2525

2626
if (!hasUserCall) {
27-
// No user call – insert an extra useFusion call that “imports” the placeholder.
27+
// No user call – insert an extra call for the placeholder without the third parameter.
2828
rewritten = wrapWithFusionImport(
2929
userCode,
3030
"const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);"
@@ -43,24 +43,19 @@ function rewrite(code, script, keys) {
4343
// Parameterless call: assume the user wants all keys.
4444
rewritten = wrapWithFusionImport(
4545
userCode.replace(regex, (m, prefix) => {
46-
return `${prefix}[${keys.map(k => `'${k}'`).join(',')}], __props.fusion)`;
46+
return `${prefix}[${keys.map(k => `'${k}'`).join(',')}], __props.fusion, true)`;
4747
})
4848
);
4949
remainingKeys = [];
5050
} else {
5151
// User provided an explicit parameter array.
52-
// Determine which keys they handled.
5352
const handledKeys = extractUseFusionParams(userCode);
5453
remainingKeys = handledKeys.includes("*")
5554
? []
5655
: keys.filter(key => !handledKeys.includes(key));
5756

58-
// Rewrite the call to append __props.fusion)
5957
const modifiedCall = modifyUseFusionCalls(userCode, keys);
60-
61-
// For inline formatting (i.e. no newline in the array) we prepend an extra call
62-
// to import the placeholder since the user is not importing all keys.
63-
// For multiline formatting, we leave the call as-is.
58+
// For inline formatting (no newline in the array), we insert an extra call above the user call.
6459
if (isMultiline) {
6560
rewritten = wrapWithFusionImport(modifiedCall);
6661
} else {
@@ -74,7 +69,7 @@ function rewrite(code, script, keys) {
7469
}
7570

7671
function checkAliasedUseFusion(code) {
77-
// Look for imports with curly braces and check if useFusion is aliased.
72+
// Look for import statements with curly braces and check if useFusion is aliased.
7873
const regex = /import\s*{([^}]+)}/gm;
7974
let match;
8075
while ((match = regex.exec(code)) !== null) {
@@ -93,7 +88,7 @@ ${extraLine ? extraLine + "\n" : ""}${content}`;
9388
}
9489

9590
function extractUseFusionParams(code) {
96-
// This regex handles both inline and multiline array formatting.
91+
// Modified regex to handle both inline and multiline arrays.
9792
const regex = /useFusion\s*\(\s*\[([\s\S]*?)\]\s*\)/g;
9893
let handledKeys = [];
9994
let match;
@@ -106,7 +101,7 @@ function extractUseFusionParams(code) {
106101
.filter(Boolean);
107102
handledKeys.push(...keysInCall);
108103
}
109-
// If a useFusion() call exists with no parameters, treat it as handling all keys.
104+
// If a useFusion call exists with no parameters, treat it as handling all keys.
110105
if (handledKeys.length === 0 && /useFusion\s*\(\s*\)/.test(code)) {
111106
return ["*"];
112107
}
@@ -117,9 +112,9 @@ function modifyUseFusionCalls(code, allKeys) {
117112
const regex = /(useFusion\s*\()(\s*\[[\s\S]*?\])?\s*\)/g;
118113
return code.replace(regex, (match, prefix, params) => {
119114
if (!params) {
120-
return `${prefix}[${allKeys.map(k => `'${k}'`).join(',')}], __props.fusion)`;
115+
return `${prefix}[${allKeys.map(k => `'${k}'`).join(',')}], __props.fusion, true)`;
121116
}
122-
return `${prefix}${params}, __props.fusion)`;
117+
return `${prefix}${params}, __props.fusion, true)`;
123118
});
124119
}
125120

packages/vue/tests/modifyScriptSetup.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('injector', () => {
7070
expect(remainingKeys).toEqual([]);
7171
expect(rewritten).toMatchCode(`
7272
import { useFusion } from "__aliasedFusionPath__";
73-
const { data } = useFusion(['name','email'], __props.fusion);
73+
const { data } = useFusion(['name','email'], __props.fusion, true);
7474
`);
7575
});
7676

@@ -88,7 +88,7 @@ describe('injector', () => {
8888
expect(rewritten).toMatchCode(`
8989
import { useFusion } from "__aliasedFusionPath__";
9090
const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);
91-
const { data } = useFusion(['name'], __props.fusion);
91+
const { data } = useFusion(['name'], __props.fusion, true);
9292
`);
9393
});
9494

@@ -106,7 +106,7 @@ describe('injector', () => {
106106
expect(rewritten).toMatchCode(`
107107
import { useFusion } from "__aliasedFusionPath__";
108108
const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);
109-
const { data } = useFusion([], __props.fusion);
109+
const { data } = useFusion([], __props.fusion, true);
110110
`);
111111
});
112112

@@ -124,7 +124,7 @@ describe('injector', () => {
124124
expect(rewritten).toMatchCode(`
125125
import { useFusion } from "__aliasedFusionPath__";
126126
const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);
127-
const { data } = useFusion ( ['name'], __props.fusion);
127+
const { data } = useFusion ( ['name'], __props.fusion, true);
128128
`);
129129
});
130130

@@ -147,7 +147,7 @@ describe('injector', () => {
147147
const { data } = useFusion([
148148
'name',
149149
'email'
150-
], __props.fusion);
150+
], __props.fusion, true);
151151
`);
152152
});
153153

@@ -169,7 +169,7 @@ describe('injector', () => {
169169
const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);
170170
import { something } from 'somewhere';
171171
import another from 'another-place';
172-
const { data } = useFusion(['name'], __props.fusion);
172+
const { data } = useFusion(['name'], __props.fusion, true);
173173
`);
174174
});
175175

@@ -187,7 +187,7 @@ describe('injector', () => {
187187
expect(rewritten).toMatchCode(`
188188
import { useFusion } from "__aliasedFusionPath__";
189189
const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);
190-
const { data } = useFusion(["name"], __props.fusion);
190+
const { data } = useFusion(["name"], __props.fusion, true);
191191
`);
192192
});
193193

@@ -205,7 +205,7 @@ describe('injector', () => {
205205
expect(rewritten).toMatchCode(`
206206
import { useFusion } from "__aliasedFusionPath__";
207207
const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);
208-
const { data } = useFusion(['name', "email"], __props.fusion);
208+
const { data } = useFusion(['name', "email"], __props.fusion, true);
209209
`);
210210
});
211211

@@ -241,7 +241,7 @@ describe('injector', () => {
241241
expect(rewritten).toMatchCode(`
242242
import { useFusion } from "__aliasedFusionPath__";
243243
const {__exportedKeysAsCsv__} = useFusion([__exportedKeysAsCsv__], __props.fusion);
244-
const data = useFusion(['name',], __props.fusion);
244+
const data = useFusion(['name',], __props.fusion, true);
245245
`);
246246
});
247247

0 commit comments

Comments
 (0)