Skip to content

Commit 86c854f

Browse files
author
Murat
committed
docs(babel_config): add js modification example
1 parent 93f65d2 commit 86c854f

File tree

15 files changed

+100
-32
lines changed

15 files changed

+100
-32
lines changed

src/__tests__/unit/utils/jsObjectParser.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ describe('jsObjectParser', () => {
103103
"
104104
`);
105105
});
106+
it('should merge append', async () => {
107+
const content = 'module.exports = { ok: 1 };';
108+
const parser = new JsObjectParser();
109+
parser.parse(content);
110+
parser.merge(
111+
{
112+
'module.exports': {
113+
ok: 2,
114+
newObj: 2,
115+
},
116+
},
117+
{ strategy: 'append' }
118+
);
119+
expect(await prettier.format(parser.stringify(), prettierConfig))
120+
.toMatchInlineSnapshot(`
121+
"module.exports = { ok: 1, newObj: 2 };
122+
"
123+
`);
124+
});
106125
it('should support partial', async () => {
107126
const content = "module.exports = { obj2: {t1: {t2: ''}, t3: 1 }};";
108127
const parser = new JsObjectParser();

src/utils/jsObjectParser.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,16 @@ export class JsObjectParser {
498498
opts.strategy === 'merge_distinct')
499499
) {
500500
this._merge(value, exprObject.tree, opts);
501-
} else {
501+
} else if (!forceAssign && opts.strategy === 'append') {
502+
const existingExpr = tree.find(expr => {
503+
return (
504+
(expr.type === 'variable' || expr.type === 'property') &&
505+
expr.name.replace(/['"[\]]/g, '') === key
506+
);
507+
}) as VariableExpression | PropertyExpression | undefined;
508+
509+
if (!existingExpr) this._merge(value, exprObject.tree, opts);
510+
} else if (opts.strategy === 'assign') {
502511
const newExpr = this._objectToExpr(value);
503512
exprObject.valueType = newExpr.valueType;
504513
exprObject.tree = newExpr.tree;

website/docs/guides/task-types/android-tasks/android-manifest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ AndroidManifest.xml modifications, including adding, updating, or deleting attri
4646
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4747
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
4848
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
49-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
49+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
5050

5151
### Other properties
5252

website/docs/guides/task-types/android-tasks/build-gradle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ changes to different sections of the `build.gradle` file.
4747
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4848
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
4949
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
50-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
50+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
5151

5252
### Other properties
5353

website/docs/guides/task-types/android-tasks/gradle-properties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The `gradle_properties` task allows you to customize gradle.properties file, whi
1313

1414
| Property | Type | Description |
1515
|:---------|:------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
16-
| task | "gradle_properties", required | Specifies the task type, which should be set to "gradle_properties" for this task. |
16+
| task | "gradle_properties", required | Specifies the task type, which should be set to "gradle_properties" for this task. |
1717
| name | string | An optional name for the task. If provided, the task state will be saved as a variable. Visit [Task and Action States](../../states) page to learn more. |
1818
| label | string | An optional label or description for the task. |
1919
| when | object | Visit [Conditional Tasks and Actions](../../when) page to learn how to execute task conditionally. |
@@ -43,7 +43,7 @@ The `gradle_properties` task allows you to customize gradle.properties file, whi
4343
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4444
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
4545
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
46-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
46+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
4747

4848
### Other properties
4949

website/docs/guides/task-types/android-tasks/main-activity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ file of the android application. This task provides the flexibility to make chan
4545
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4646
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
4747
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
48-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
48+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
4949

5050
### Other properties
5151

website/docs/guides/task-types/android-tasks/main-application.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ kotlin file.
4646
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4747
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
4848
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
49-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
49+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
5050

5151
### Other properties
5252

website/docs/guides/task-types/android-tasks/settings-gradle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ the android application. This task provides the flexibility to make changes to d
4444
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4545
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
4646
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
47-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
47+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
4848

4949
### Other properties
5050

website/docs/guides/task-types/android-tasks/strings-xml.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The `strings_xml` task allows you to modify the strings.xml file in an Android p
4343
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4444
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
4545
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
46-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
46+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
4747

4848
### Other properties
4949

website/docs/guides/task-types/ios-tasks/app_delegate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ task is particularly useful for integrating third-party libraries or SDKs that r
4848
| prepend | string or `{file: string}` | Text or code to prepend at the beginning of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to prepend. |
4949
| append | string or `{file: string}` | Text or code to append at the end of the specified context. It can be a string or an object with a `file` field that points to a file containing the code to append. |
5050
| replace | string or `{file: string}` | Text or code to replace the entire specified context. It can be a string or an object with a `file` field that points to a file containing the code to replace. |
51-
| script | string or `{file: string}` | JS code script to evaluate. It can be a string or an object with a `file` field that points to a file containing the script. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
51+
| script | string | JS code script to evaluate. In script these functions are available to be called: `await prepend(content), await append(content), await replace(content) |
5252

5353
### Other properties
5454

0 commit comments

Comments
 (0)