@plaudit/webpack-extensions 2.60.1 → 2.60.2
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/build/utils/php-writer.d.ts +3 -1
- package/build/utils/php-writer.js +16 -12
- package/package.json +1 -1
|
@@ -25,12 +25,13 @@ export declare class PHPWriter {
|
|
|
25
25
|
private readonly scopeStack;
|
|
26
26
|
private readonly useList;
|
|
27
27
|
private readonly allocatedGeneratedFunctionNames;
|
|
28
|
+
private readonly isSubwriter;
|
|
28
29
|
private printingInPHP;
|
|
29
30
|
private buffer;
|
|
30
31
|
private indentation;
|
|
31
32
|
private fileNamespace;
|
|
32
33
|
private myOpenedScopes;
|
|
33
|
-
constructor(inlineFirstLine?: boolean, scopeStack?: string[][], useList?: string[], allocatedGeneratedFunctionNames?: Set<string>, printingInPHP?: boolean, initialIndentation?: number);
|
|
34
|
+
constructor(inlineFirstLine?: boolean, scopeStack?: string[][], useList?: string[], allocatedGeneratedFunctionNames?: Set<string>, isSubwriter?: boolean, printingInPHP?: boolean, initialIndentation?: number);
|
|
34
35
|
createSubwriter(): PHPWriter;
|
|
35
36
|
indent(): this;
|
|
36
37
|
outdent(): this;
|
|
@@ -85,6 +86,7 @@ export declare class PHPWriter {
|
|
|
85
86
|
}): this;
|
|
86
87
|
toString(args?: {
|
|
87
88
|
includeOpenPHP?: boolean;
|
|
89
|
+
includeNamespaceAndUse?: boolean;
|
|
88
90
|
}): string;
|
|
89
91
|
emitAsset(compilation: Compilation, file: string, assetInfo?: AssetInfo): void;
|
|
90
92
|
}
|
|
@@ -25,21 +25,23 @@ class PHPWriter {
|
|
|
25
25
|
scopeStack;
|
|
26
26
|
useList;
|
|
27
27
|
allocatedGeneratedFunctionNames;
|
|
28
|
+
isSubwriter;
|
|
28
29
|
printingInPHP;
|
|
29
30
|
buffer = [];
|
|
30
31
|
indentation;
|
|
31
32
|
fileNamespace = "";
|
|
32
33
|
myOpenedScopes = 0;
|
|
33
|
-
constructor(inlineFirstLine = false, scopeStack = [], useList = [], allocatedGeneratedFunctionNames = new Set(), printingInPHP = true, initialIndentation = 0) {
|
|
34
|
+
constructor(inlineFirstLine = false, scopeStack = [], useList = [], allocatedGeneratedFunctionNames = new Set(), isSubwriter = false, printingInPHP = true, initialIndentation = 0) {
|
|
34
35
|
this.inlineFirstLine = inlineFirstLine;
|
|
35
36
|
this.scopeStack = scopeStack;
|
|
36
37
|
this.useList = useList;
|
|
37
38
|
this.allocatedGeneratedFunctionNames = allocatedGeneratedFunctionNames;
|
|
39
|
+
this.isSubwriter = isSubwriter;
|
|
38
40
|
this.printingInPHP = printingInPHP;
|
|
39
41
|
this.indentation = "\t".repeat(initialIndentation);
|
|
40
42
|
}
|
|
41
43
|
createSubwriter() {
|
|
42
|
-
return new PHPWriter(false, this.scopeStack, this.useList, this.allocatedGeneratedFunctionNames, this.printingInPHP, this.indentation.length)
|
|
44
|
+
return new PHPWriter(false, this.scopeStack, this.useList, this.allocatedGeneratedFunctionNames, true, this.printingInPHP, this.indentation.length)
|
|
43
45
|
.setIndentation(this.indentation.length);
|
|
44
46
|
}
|
|
45
47
|
indent() {
|
|
@@ -127,13 +129,13 @@ class PHPWriter {
|
|
|
127
129
|
}
|
|
128
130
|
this.openPHP().openScope();
|
|
129
131
|
const functionName = functionWriter.function(true, functionArgParameters, contents, { useVars, scopeActionDescription: `closing the function call for the ${name} ${type}.`, assignToName: true });
|
|
130
|
-
this.append(functionWriter.toString(
|
|
132
|
+
this.append(functionWriter.toString().trim());
|
|
131
133
|
declarationFunctionText = functionName + "(...)";
|
|
132
134
|
this.if(`doing_${type}(${Expr.convertJsonToPHP(name)})`).call(functionName, accountForAlreadyDoing === true ? [] : accountForAlreadyDoing);
|
|
133
135
|
}
|
|
134
136
|
else {
|
|
135
137
|
functionWriter.function(false, functionArgParameters, contents, { useVars, scopeActionDescription: `closing the function call for the ${name} ${type}.` });
|
|
136
|
-
declarationFunctionText = functionWriter.toString(
|
|
138
|
+
declarationFunctionText = functionWriter.toString().trim();
|
|
137
139
|
}
|
|
138
140
|
// The trailing comma inside the first item is necessary
|
|
139
141
|
const declarationComponents = [`${Expr.convertJsonToPHP(name)}`, declarationFunctionText];
|
|
@@ -307,19 +309,21 @@ class PHPWriter {
|
|
|
307
309
|
}
|
|
308
310
|
return this;
|
|
309
311
|
}
|
|
310
|
-
toString(args = {}) {
|
|
312
|
+
toString(args = this.isSubwriter ? { includeOpenPHP: false, includeNamespaceAndUse: false } : {}) {
|
|
311
313
|
if (this.myOpenedScopes) {
|
|
312
314
|
console.trace("toString() was called on a PHPWriter that has a dangling scope");
|
|
313
315
|
}
|
|
314
316
|
const fileContents = [];
|
|
315
317
|
let canInline = true;
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
318
|
+
if (args.includeNamespaceAndUse !== false) {
|
|
319
|
+
if (this.fileNamespace) {
|
|
320
|
+
canInline = false;
|
|
321
|
+
fileContents.push(`namespace ${this.fileNamespace};`);
|
|
322
|
+
}
|
|
323
|
+
if (this.useList.length) {
|
|
324
|
+
canInline = false;
|
|
325
|
+
fileContents.push(...this.useList.map(use => `use ${use};`));
|
|
326
|
+
}
|
|
323
327
|
}
|
|
324
328
|
fileContents.push(...this.buffer);
|
|
325
329
|
if (args.includeOpenPHP === false) {
|