@zackad/prettier-plugin-twig 0.7.0-alpha.1 → 0.7.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 +5 -7
- package/package.json +10 -8
- package/src/index.js +53 -53
- package/src/melody/melody-code-frame/index.js +44 -0
- package/src/melody/melody-code-frame/lineNumbers.js +45 -0
- package/src/melody/melody-extension-core/index.js +167 -0
- package/src/melody/melody-extension-core/operators.js +414 -0
- package/src/melody/melody-extension-core/parser/autoescape.js +92 -0
- package/src/melody/melody-extension-core/parser/block.js +93 -0
- package/src/melody/melody-extension-core/parser/do.js +32 -0
- package/src/melody/melody-extension-core/parser/embed.js +76 -0
- package/src/melody/melody-extension-core/parser/extends.js +35 -0
- package/src/melody/melody-extension-core/parser/filter.js +63 -0
- package/src/melody/melody-extension-core/parser/flush.js +33 -0
- package/src/melody/melody-extension-core/parser/for.js +110 -0
- package/src/melody/melody-extension-core/parser/from.js +63 -0
- package/src/melody/melody-extension-core/parser/if.js +100 -0
- package/src/melody/melody-extension-core/parser/import.js +44 -0
- package/src/melody/melody-extension-core/parser/include.js +48 -0
- package/src/melody/melody-extension-core/parser/macro.js +94 -0
- package/src/melody/melody-extension-core/parser/mount.js +147 -0
- package/src/melody/melody-extension-core/parser/set.js +103 -0
- package/src/melody/melody-extension-core/parser/spaceless.js +56 -0
- package/src/melody/melody-extension-core/parser/use.js +58 -0
- package/src/melody/melody-extension-core/types.js +402 -0
- package/src/melody/melody-extension-core/visitors/filters.js +146 -0
- package/src/melody/melody-extension-core/visitors/for.js +391 -0
- package/src/melody/melody-extension-core/visitors/functions.js +100 -0
- package/src/melody/melody-extension-core/visitors/tests.js +127 -0
- package/src/melody/melody-parser/Associativity.js +17 -0
- package/src/melody/melody-parser/CharStream.js +82 -0
- package/src/melody/melody-parser/GenericMultiTagParser.js +66 -0
- package/src/melody/melody-parser/GenericTagParser.js +53 -0
- package/src/melody/melody-parser/Lexer.js +708 -0
- package/src/melody/melody-parser/Parser.js +954 -0
- package/src/melody/melody-parser/TokenStream.js +183 -0
- package/src/melody/melody-parser/TokenTypes.js +74 -0
- package/src/melody/melody-parser/elementInfo.js +43 -0
- package/src/melody/melody-parser/index.js +94 -0
- package/src/melody/melody-parser/util.js +100 -0
- package/src/melody/melody-traverse/Binding.js +61 -0
- package/src/melody/melody-traverse/Path.js +427 -0
- package/src/melody/melody-traverse/Scope.js +218 -0
- package/src/melody/melody-traverse/TraversalContext.js +166 -0
- package/src/melody/melody-traverse/index.js +21 -0
- package/src/melody/melody-traverse/traverse.js +48 -0
- package/src/melody/melody-traverse/visitors.js +112 -0
- package/src/melody/melody-types/index.js +506 -0
- package/src/parser.js +7 -2
- package/src/print/Attribute.js +1 -1
- package/src/print/BinaryExpression.js +2 -2
- package/src/print/BlockStatement.js +1 -1
- package/src/print/CallExpression.js +1 -1
- package/src/print/ExpressionStatement.js +1 -1
- package/src/print/FilterExpression.js +1 -1
- package/src/print/GenericTwigTag.js +1 -1
- package/src/print/IfStatement.js +1 -1
- package/src/print/ObjectProperty.js +1 -1
- package/src/print/SetStatement.js +1 -1
- package/src/print/SwitchTag.js +1 -1
- package/src/print/UnarySubclass.js +1 -1
- package/src/util/printFunctions.js +1 -1
- package/src/util/publicFunctions.js +1 -1
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2017 trivago N.V.
|
|
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
|
+
|
|
17
|
+
import * as t from "@babel/types";
|
|
18
|
+
|
|
19
|
+
export const TYPE_MAP = Object.create(null);
|
|
20
|
+
export const ALIAS_TO_TYPE = Object.create(null);
|
|
21
|
+
export const PATH_CACHE_KEY = Symbol("PATH_CACHE_KEY");
|
|
22
|
+
|
|
23
|
+
const IS_ALIAS_OF = Object.create(null);
|
|
24
|
+
|
|
25
|
+
export class Node {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.loc = {
|
|
28
|
+
source: null,
|
|
29
|
+
start: { line: 0, column: 0 },
|
|
30
|
+
end: { line: 0, column: 0 }
|
|
31
|
+
};
|
|
32
|
+
this[PATH_CACHE_KEY] = [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
toJSON() {
|
|
36
|
+
return Object.getOwnPropertyNames(this).reduce(
|
|
37
|
+
(acc, name) => {
|
|
38
|
+
if (name === "loc" || name === "parent") {
|
|
39
|
+
return acc;
|
|
40
|
+
}
|
|
41
|
+
const value = this[name];
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
acc[name] = value.map(val => val.toJSON());
|
|
44
|
+
} else {
|
|
45
|
+
acc[name] = value && value.toJSON ? value.toJSON() : value;
|
|
46
|
+
}
|
|
47
|
+
return acc;
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: this.type
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static registerType(type) {
|
|
56
|
+
if (Node["is" + type]) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Node["is" + type] = function (node) {
|
|
61
|
+
return is(node, type);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Node['assert' + type] = function(node) {
|
|
65
|
+
// if (!is(node, type)) {
|
|
66
|
+
// throw new Error('Expected node to be of type ' + type + ' but was ' + (node ? node.type : 'undefined') + ' instead');
|
|
67
|
+
// }
|
|
68
|
+
// };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
Node.registerType("Scope");
|
|
72
|
+
|
|
73
|
+
export function is(node, type) {
|
|
74
|
+
if (!node) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
node.type === type ||
|
|
80
|
+
(IS_ALIAS_OF[type] && IS_ALIAS_OF[type][node.type]) ||
|
|
81
|
+
t.is(type, node)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {...string} fields
|
|
87
|
+
*/
|
|
88
|
+
export function visitor(type, ...fields) {
|
|
89
|
+
type.prototype.visitorKeys = fields;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param {...string} aliases
|
|
94
|
+
*/
|
|
95
|
+
export function alias(type, ...aliases) {
|
|
96
|
+
type.prototype.aliases = aliases;
|
|
97
|
+
for (let i = 0, len = aliases.length; i < len; i++) {
|
|
98
|
+
const alias = aliases[i];
|
|
99
|
+
if (!ALIAS_TO_TYPE[alias]) {
|
|
100
|
+
ALIAS_TO_TYPE[alias] = [];
|
|
101
|
+
}
|
|
102
|
+
ALIAS_TO_TYPE[alias].push(type.prototype.type);
|
|
103
|
+
if (!IS_ALIAS_OF[alias]) {
|
|
104
|
+
IS_ALIAS_OF[alias] = {};
|
|
105
|
+
}
|
|
106
|
+
IS_ALIAS_OF[alias][type.prototype.type] = true;
|
|
107
|
+
Node.registerType(alias);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {...string} type
|
|
113
|
+
*/
|
|
114
|
+
export function type(Type, type) {
|
|
115
|
+
Type.prototype.type = type;
|
|
116
|
+
TYPE_MAP[type] = Type;
|
|
117
|
+
|
|
118
|
+
Node.registerType(type);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export class Fragment extends Node {
|
|
122
|
+
/**
|
|
123
|
+
* @param {Node} expression
|
|
124
|
+
*/
|
|
125
|
+
constructor(expression) {
|
|
126
|
+
super();
|
|
127
|
+
this.value = expression;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
type(Fragment, "Fragment");
|
|
131
|
+
alias(Fragment, "Statement");
|
|
132
|
+
visitor(Fragment, "value");
|
|
133
|
+
|
|
134
|
+
export class PrintExpressionStatement extends Node {
|
|
135
|
+
/**
|
|
136
|
+
* @param {Node} expression
|
|
137
|
+
*/
|
|
138
|
+
constructor(expression) {
|
|
139
|
+
super();
|
|
140
|
+
this.value = expression;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
type(PrintExpressionStatement, "PrintExpressionStatement");
|
|
144
|
+
alias(PrintExpressionStatement, "Statement", "PrintStatement");
|
|
145
|
+
visitor(PrintExpressionStatement, "value");
|
|
146
|
+
|
|
147
|
+
export class PrintTextStatement extends Node {
|
|
148
|
+
/**
|
|
149
|
+
* @param {StringLiteral} text
|
|
150
|
+
*/
|
|
151
|
+
constructor(text) {
|
|
152
|
+
super();
|
|
153
|
+
this.value = text;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
type(PrintTextStatement, "PrintTextStatement");
|
|
157
|
+
alias(PrintTextStatement, "Statement", "PrintStatement");
|
|
158
|
+
visitor(PrintTextStatement, "value");
|
|
159
|
+
|
|
160
|
+
export class ConstantValue extends Node {
|
|
161
|
+
constructor(value) {
|
|
162
|
+
super();
|
|
163
|
+
this.value = value;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
toString() {
|
|
167
|
+
return `Const(${this.value})`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
type(ConstantValue, "ConstantValue");
|
|
171
|
+
alias(ConstantValue, "Expression", "Literal", "Immutable");
|
|
172
|
+
|
|
173
|
+
export class StringLiteral extends ConstantValue {}
|
|
174
|
+
type(StringLiteral, "StringLiteral");
|
|
175
|
+
alias(StringLiteral, "Expression", "Literal", "Immutable");
|
|
176
|
+
|
|
177
|
+
export class NumericLiteral extends ConstantValue {}
|
|
178
|
+
type(NumericLiteral, "NumericLiteral");
|
|
179
|
+
alias(NumericLiteral, "Expression", "Literal", "Immutable");
|
|
180
|
+
|
|
181
|
+
export class BooleanLiteral extends ConstantValue {
|
|
182
|
+
constructor(value) {
|
|
183
|
+
super(value);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
type(BooleanLiteral, "BooleanLiteral");
|
|
187
|
+
alias(BooleanLiteral, "Expression", "Literal", "Immutable");
|
|
188
|
+
|
|
189
|
+
export class NullLiteral extends ConstantValue {
|
|
190
|
+
constructor() {
|
|
191
|
+
super(null);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
type(NullLiteral, "NullLiteral");
|
|
195
|
+
alias(NullLiteral, "Expression", "Literal", "Immutable");
|
|
196
|
+
|
|
197
|
+
export class Identifier extends Node {
|
|
198
|
+
constructor(name) {
|
|
199
|
+
super();
|
|
200
|
+
this.name = name;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
type(Identifier, "Identifier");
|
|
204
|
+
alias(Identifier, "Expression");
|
|
205
|
+
|
|
206
|
+
export class UnaryExpression extends Node {
|
|
207
|
+
/**
|
|
208
|
+
* @param {String} operator
|
|
209
|
+
* @param {Node} argument
|
|
210
|
+
*/
|
|
211
|
+
constructor(operator, argument) {
|
|
212
|
+
super();
|
|
213
|
+
this.operator = operator;
|
|
214
|
+
this.argument = argument;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
type(UnaryExpression, "UnaryExpression");
|
|
218
|
+
alias(UnaryExpression, "Expression", "UnaryLike");
|
|
219
|
+
visitor(UnaryExpression, "argument");
|
|
220
|
+
|
|
221
|
+
export class BinaryExpression extends Node {
|
|
222
|
+
/**
|
|
223
|
+
* @param {String} operator
|
|
224
|
+
* @param {Node} left
|
|
225
|
+
* @param {Node} right
|
|
226
|
+
*/
|
|
227
|
+
constructor(operator, left, right) {
|
|
228
|
+
super();
|
|
229
|
+
this.operator = operator;
|
|
230
|
+
this.left = left;
|
|
231
|
+
this.right = right;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
type(BinaryExpression, "BinaryExpression");
|
|
235
|
+
alias(BinaryExpression, "Binary", "Expression");
|
|
236
|
+
visitor(BinaryExpression, "left", "right");
|
|
237
|
+
|
|
238
|
+
export class BinaryConcatExpression extends BinaryExpression {
|
|
239
|
+
/**
|
|
240
|
+
* @param {Node} left
|
|
241
|
+
* @param {Node} right
|
|
242
|
+
*/
|
|
243
|
+
constructor(left, right) {
|
|
244
|
+
super("~", left, right);
|
|
245
|
+
this.wasImplicitConcatenation = false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
type(BinaryConcatExpression, "BinaryConcatExpression");
|
|
249
|
+
alias(BinaryConcatExpression, "BinaryExpression", "Binary", "Expression");
|
|
250
|
+
visitor(BinaryConcatExpression, "left", "right");
|
|
251
|
+
|
|
252
|
+
export class ConditionalExpression extends Node {
|
|
253
|
+
/**
|
|
254
|
+
* @param {Node} test
|
|
255
|
+
* @param {Node} consequent
|
|
256
|
+
* @param {Node} alternate
|
|
257
|
+
*/
|
|
258
|
+
constructor(test, consequent, alternate) {
|
|
259
|
+
super();
|
|
260
|
+
this.test = test;
|
|
261
|
+
this.consequent = consequent;
|
|
262
|
+
this.alternate = alternate;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
type(ConditionalExpression, "ConditionalExpression");
|
|
266
|
+
alias(ConditionalExpression, "Expression", "Conditional");
|
|
267
|
+
visitor(ConditionalExpression, "test", "consequent", "alternate");
|
|
268
|
+
|
|
269
|
+
export class ArrayExpression extends Node {
|
|
270
|
+
constructor(elements = []) {
|
|
271
|
+
super();
|
|
272
|
+
this.elements = elements;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
type(ArrayExpression, "ArrayExpression");
|
|
276
|
+
alias(ArrayExpression, "Expression");
|
|
277
|
+
visitor(ArrayExpression, "elements");
|
|
278
|
+
|
|
279
|
+
export class MemberExpression extends Node {
|
|
280
|
+
/**
|
|
281
|
+
* @param {Node} object
|
|
282
|
+
* @param {Node} property
|
|
283
|
+
* @param {boolean} computed
|
|
284
|
+
*/
|
|
285
|
+
constructor(object, property, computed) {
|
|
286
|
+
super();
|
|
287
|
+
this.object = object;
|
|
288
|
+
this.property = property;
|
|
289
|
+
this.computed = computed;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
type(MemberExpression, "MemberExpression");
|
|
293
|
+
alias(MemberExpression, "Expression", "LVal");
|
|
294
|
+
visitor(MemberExpression, "object", "property");
|
|
295
|
+
|
|
296
|
+
export class CallExpression extends Node {
|
|
297
|
+
/**
|
|
298
|
+
* @param {Node} callee
|
|
299
|
+
* @param {Array<Node>} args
|
|
300
|
+
*/
|
|
301
|
+
constructor(callee, args) {
|
|
302
|
+
super();
|
|
303
|
+
this.callee = callee;
|
|
304
|
+
this.arguments = args;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
type(CallExpression, "CallExpression");
|
|
308
|
+
alias(CallExpression, "Expression", "FunctionInvocation");
|
|
309
|
+
visitor(CallExpression, "callee", "arguments");
|
|
310
|
+
|
|
311
|
+
export class NamedArgumentExpression extends Node {
|
|
312
|
+
/**
|
|
313
|
+
* @param {Identifier} name
|
|
314
|
+
* @param {Node} value
|
|
315
|
+
*/
|
|
316
|
+
constructor(name, value) {
|
|
317
|
+
super();
|
|
318
|
+
this.name = name;
|
|
319
|
+
this.value = value;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
type(NamedArgumentExpression, "NamedArgumentExpression");
|
|
323
|
+
alias(NamedArgumentExpression, "Expression");
|
|
324
|
+
visitor(NamedArgumentExpression, "name", "value");
|
|
325
|
+
|
|
326
|
+
export class ObjectExpression extends Node {
|
|
327
|
+
/**
|
|
328
|
+
* @param {Array<ObjectProperty>} properties
|
|
329
|
+
*/
|
|
330
|
+
constructor(properties = []) {
|
|
331
|
+
super();
|
|
332
|
+
this.properties = properties;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
type(ObjectExpression, "ObjectExpression");
|
|
336
|
+
alias(ObjectExpression, "Expression");
|
|
337
|
+
visitor(ObjectExpression, "properties");
|
|
338
|
+
|
|
339
|
+
export class ObjectProperty extends Node {
|
|
340
|
+
/**
|
|
341
|
+
* @param {Node} key
|
|
342
|
+
* @param {Node} value
|
|
343
|
+
* @param {boolean} computed
|
|
344
|
+
*/
|
|
345
|
+
constructor(key, value, computed) {
|
|
346
|
+
super();
|
|
347
|
+
this.key = key;
|
|
348
|
+
this.value = value;
|
|
349
|
+
this.computed = computed;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
type(ObjectProperty, "ObjectProperty");
|
|
353
|
+
alias(ObjectProperty, "Property", "ObjectMember");
|
|
354
|
+
visitor(ObjectProperty, "key", "value");
|
|
355
|
+
|
|
356
|
+
export class SequenceExpression extends Node {
|
|
357
|
+
/**
|
|
358
|
+
* @param {Array<Node>} expressions
|
|
359
|
+
*/
|
|
360
|
+
constructor(expressions = []) {
|
|
361
|
+
super();
|
|
362
|
+
this.expressions = expressions;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* @param {Node} child
|
|
367
|
+
*/
|
|
368
|
+
add(child) {
|
|
369
|
+
this.expressions.push(child);
|
|
370
|
+
this.loc.end = child.loc.end;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
type(SequenceExpression, "SequenceExpression");
|
|
374
|
+
alias(SequenceExpression, "Expression", "Scope");
|
|
375
|
+
visitor(SequenceExpression, "expressions");
|
|
376
|
+
|
|
377
|
+
export class SliceExpression extends Node {
|
|
378
|
+
/**
|
|
379
|
+
* @param {Node} target
|
|
380
|
+
* @param {Node} start
|
|
381
|
+
* @param {Node} end
|
|
382
|
+
*/
|
|
383
|
+
constructor(target, start, end) {
|
|
384
|
+
super();
|
|
385
|
+
this.target = target;
|
|
386
|
+
this.start = start;
|
|
387
|
+
this.end = end;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
type(SliceExpression, "SliceExpression");
|
|
391
|
+
alias(SliceExpression, "Expression");
|
|
392
|
+
visitor(SliceExpression, "source", "start", "end");
|
|
393
|
+
|
|
394
|
+
export class FilterExpression extends Node {
|
|
395
|
+
/**
|
|
396
|
+
* @param {Node} target
|
|
397
|
+
* @param {Identifier} name
|
|
398
|
+
* @param {Array<Node>} args
|
|
399
|
+
*/
|
|
400
|
+
constructor(target, name, args) {
|
|
401
|
+
super();
|
|
402
|
+
this.target = target;
|
|
403
|
+
this.name = name;
|
|
404
|
+
this.arguments = args;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
type(FilterExpression, "FilterExpression");
|
|
408
|
+
alias(FilterExpression, "Expression");
|
|
409
|
+
visitor(FilterExpression, "target", "arguments");
|
|
410
|
+
|
|
411
|
+
export class Element extends Node {
|
|
412
|
+
/**
|
|
413
|
+
* @param {String} name
|
|
414
|
+
*/
|
|
415
|
+
constructor(name) {
|
|
416
|
+
super();
|
|
417
|
+
this.name = name;
|
|
418
|
+
this.attributes = [];
|
|
419
|
+
this.children = [];
|
|
420
|
+
this.selfClosing = false;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
type(Element, "Element");
|
|
424
|
+
alias(Element, "Expression");
|
|
425
|
+
visitor(Element, "attributes", "children");
|
|
426
|
+
|
|
427
|
+
export class Attribute extends Node {
|
|
428
|
+
/**
|
|
429
|
+
* @param {Node} name
|
|
430
|
+
* @param {Node} value
|
|
431
|
+
*/
|
|
432
|
+
constructor(name, value = null) {
|
|
433
|
+
super();
|
|
434
|
+
this.name = name;
|
|
435
|
+
this.value = value;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
isImmutable() {
|
|
439
|
+
return is(this.name, "Identifier") && is(this.value, "Immutable");
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
type(Attribute, "Attribute");
|
|
443
|
+
visitor(Attribute, "name", "value");
|
|
444
|
+
|
|
445
|
+
export class TwigComment extends Node {
|
|
446
|
+
/**
|
|
447
|
+
* @param {StringLiteral} text
|
|
448
|
+
*/
|
|
449
|
+
constructor(text) {
|
|
450
|
+
super();
|
|
451
|
+
this.value = text;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
type(TwigComment, "TwigComment");
|
|
455
|
+
visitor(TwigComment, "value");
|
|
456
|
+
|
|
457
|
+
export class HtmlComment extends Node {
|
|
458
|
+
/**
|
|
459
|
+
* @param {StringLiteral} text
|
|
460
|
+
*/
|
|
461
|
+
constructor(text) {
|
|
462
|
+
super();
|
|
463
|
+
this.value = text;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
type(HtmlComment, "HtmlComment");
|
|
467
|
+
visitor(HtmlComment, "value");
|
|
468
|
+
|
|
469
|
+
export class Declaration extends Node {
|
|
470
|
+
/**
|
|
471
|
+
* @param {String} declarationType
|
|
472
|
+
*/
|
|
473
|
+
constructor(declarationType) {
|
|
474
|
+
super();
|
|
475
|
+
this.declarationType = declarationType;
|
|
476
|
+
this.parts = [];
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
type(Declaration, "Declaration");
|
|
480
|
+
visitor(Declaration, "parts");
|
|
481
|
+
|
|
482
|
+
export class GenericTwigTag extends Node {
|
|
483
|
+
/**
|
|
484
|
+
* @param {String} tagName
|
|
485
|
+
*/
|
|
486
|
+
constructor(tagName) {
|
|
487
|
+
super();
|
|
488
|
+
this.tagName = tagName;
|
|
489
|
+
this.parts = [];
|
|
490
|
+
this.sections = [];
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
type(GenericTwigTag, "GenericTwigTag");
|
|
494
|
+
|
|
495
|
+
export class GenericToken extends Node {
|
|
496
|
+
/**
|
|
497
|
+
* @param {String} tokenType
|
|
498
|
+
* @param {String} tokenText
|
|
499
|
+
*/
|
|
500
|
+
constructor(tokenType, tokenText) {
|
|
501
|
+
super();
|
|
502
|
+
this.tokenType = tokenType;
|
|
503
|
+
this.tokenText = tokenText;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
type(GenericToken, "GenericToken");
|
package/src/parser.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CharStream,
|
|
3
|
+
Lexer,
|
|
4
|
+
TokenStream,
|
|
5
|
+
Parser
|
|
6
|
+
} from "./melody/melody-parser/index.js";
|
|
7
|
+
import { extension as coreExtension } from "./melody/melody-extension-core/index.js";
|
|
3
8
|
|
|
4
9
|
const ORIGINAL_SOURCE = Symbol("ORIGINAL_SOURCE");
|
|
5
10
|
|
package/src/print/Attribute.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { doc } from "prettier";
|
|
2
|
-
import { Node } from "melody-types";
|
|
3
|
-
import { extension as coreExtension } from "melody-extension-core";
|
|
2
|
+
import { Node } from "../melody/melody-types/index.js";
|
|
3
|
+
import { extension as coreExtension } from "../melody/melody-extension-core/index.js";
|
|
4
4
|
import {
|
|
5
5
|
EXPRESSION_NEEDED,
|
|
6
6
|
STRING_NEEDS_QUOTES,
|
package/src/print/IfStatement.js
CHANGED
package/src/print/SwitchTag.js
CHANGED