@sap/cds-compiler 2.4.4 → 2.10.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/CHANGELOG.md +241 -1
- package/bin/.eslintrc.json +17 -0
- package/bin/cds_update_identifiers.js +8 -7
- package/bin/cdsc.js +180 -132
- package/bin/cdshi.js +18 -11
- package/bin/cdsse.js +38 -32
- package/bin/cdsv2m.js +8 -7
- package/doc/CHANGELOG_BETA.md +36 -1
- package/lib/api/main.js +81 -100
- package/lib/api/options.js +17 -11
- package/lib/api/validate.js +12 -8
- package/lib/backends.js +0 -81
- package/lib/base/keywords.js +32 -2
- package/lib/base/location.js +2 -2
- package/lib/base/message-registry.js +66 -4
- package/lib/base/messages.js +84 -27
- package/lib/base/model.js +2 -61
- package/lib/checks/arrayOfs.js +0 -1
- package/lib/checks/defaultValues.js +27 -2
- package/lib/checks/elements.js +1 -6
- package/lib/checks/enricher.js +8 -2
- package/lib/checks/foreignKeys.js +0 -6
- package/lib/checks/managedWithoutKeys.js +17 -0
- package/lib/checks/nonexpandableStructured.js +38 -0
- package/lib/checks/onConditions.js +9 -45
- package/lib/checks/queryNoDbArtifacts.js +27 -9
- package/lib/checks/selectItems.js +25 -2
- package/lib/checks/types.js +26 -2
- package/lib/checks/unknownMagic.js +38 -0
- package/lib/checks/utils.js +61 -0
- package/lib/checks/validator.js +66 -13
- package/lib/compiler/assert-consistency.js +24 -12
- package/lib/compiler/builtins.js +2 -0
- package/lib/compiler/checks.js +6 -4
- package/lib/compiler/definer.js +101 -39
- package/lib/compiler/index.js +88 -59
- package/lib/compiler/resolver.js +455 -209
- package/lib/compiler/shared.js +57 -33
- package/lib/edm/annotations/genericTranslation.js +183 -187
- package/lib/edm/csn2edm.js +128 -99
- package/lib/edm/edm.js +18 -21
- package/lib/edm/edmPreprocessor.js +361 -127
- package/lib/edm/edmUtils.js +103 -33
- package/lib/gen/Dictionary.json +74 -28
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +18 -4
- package/lib/gen/language.tokens +124 -118
- package/lib/gen/languageLexer.interp +13 -1
- package/lib/gen/languageLexer.js +870 -839
- package/lib/gen/languageLexer.tokens +116 -111
- package/lib/gen/languageParser.js +5894 -5614
- package/lib/json/from-csn.js +152 -67
- package/lib/json/to-csn.js +334 -135
- package/lib/language/antlrParser.js +4 -3
- package/lib/language/errorStrategy.js +1 -0
- package/lib/language/genericAntlrParser.js +24 -14
- package/lib/language/language.g4 +188 -128
- package/lib/main.d.ts +435 -0
- package/lib/main.js +31 -7
- package/lib/model/api.js +78 -0
- package/lib/model/csnRefs.js +463 -187
- package/lib/model/csnUtils.js +280 -136
- package/lib/model/enrichCsn.js +75 -4
- package/lib/model/revealInternalProperties.js +2 -1
- package/lib/modelCompare/compare.js +70 -25
- package/lib/optionProcessor.js +13 -10
- package/lib/render/.eslintrc.json +4 -1
- package/lib/render/DuplicateChecker.js +8 -5
- package/lib/render/toCdl.js +123 -40
- package/lib/render/toHdbcds.js +156 -65
- package/lib/render/toSql.js +87 -11
- package/lib/render/utils/common.js +55 -9
- package/lib/render/utils/sql.js +3 -3
- package/lib/sql-identifier.js +6 -1
- package/lib/transform/{sql → db}/.eslintrc.json +0 -0
- package/lib/transform/{sql → db}/assertUnique.js +7 -8
- package/lib/transform/{sql → db}/constraints.js +35 -20
- package/lib/transform/db/draft.js +353 -0
- package/lib/transform/db/expansion.js +582 -0
- package/lib/transform/db/flattening.js +325 -0
- package/lib/transform/{sql → db}/groupByOrderBy.js +8 -16
- package/lib/transform/{sql → db}/helpers.js +0 -0
- package/lib/transform/{sql → db}/transformExists.js +256 -60
- package/lib/transform/forHanaNew.js +216 -765
- package/lib/transform/forOdataNew.js +60 -56
- package/lib/transform/localized.js +48 -26
- package/lib/transform/odata/attachPath.js +19 -4
- package/lib/transform/odata/expandStructKeysInAssociations.js +2 -2
- package/lib/transform/odata/generateForeignKeyElements.js +13 -12
- package/lib/transform/odata/referenceFlattener.js +60 -36
- package/lib/transform/odata/sortByAssociationDependency.js +4 -4
- package/lib/transform/odata/structuralPath.js +76 -0
- package/lib/transform/odata/structureFlattener.js +21 -22
- package/lib/transform/odata/toFinalBaseType.js +5 -5
- package/lib/transform/odata/typesExposure.js +27 -17
- package/lib/transform/odata/utils.js +2 -2
- package/lib/transform/transformUtilsNew.js +141 -77
- package/lib/transform/translateAssocsToJoins.js +17 -14
- package/lib/transform/universalCsnEnricher.js +67 -0
- package/lib/utils/file.js +0 -11
- package/lib/utils/moduleResolve.js +6 -8
- package/lib/utils/timetrace.js +6 -1
- package/package.json +2 -1
- package/lib/base/deepCopy.js +0 -66
- package/lib/json/walker.js +0 -26
- package/lib/utils/string.js +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -7,12 +7,235 @@
|
|
|
7
7
|
Note: `beta` fixes, changes and features are usually not listed in this ChangeLog but [here](doc/CHANGELOG_BETA.md).
|
|
8
8
|
The compiler behavior concerning `beta` features can change at any time without notice.
|
|
9
9
|
|
|
10
|
+
## Version 2.10.2 - 2021-10-29
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- to.sql/hdi/hdbcds: Correctly handle `exists` in conjunction with mixin-associations
|
|
15
|
+
|
|
16
|
+
## Version 2.10.0 - 2021-10-28
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Support arbitrary paths after `$user` - similar to `$session`.
|
|
21
|
+
- Support scale `floating` and `variable` for `cds.Decimal` in CDL and CSN. Backend specific handling is descibed in their sections.
|
|
22
|
+
- Allow select item wildcard (`*`) in a `select`/`projection` at any position, not just the first.
|
|
23
|
+
|
|
24
|
+
- to.edm(x):
|
|
25
|
+
+ In Odata V4 generate transitive navigation property binding paths along containment hierarchies and terminate on the
|
|
26
|
+
first non-containment association. The association target is either an explicit Edm.EntitySet in the same EntityContainer
|
|
27
|
+
or in a referred EntityContainer (cross service references) or an implicit EntitySet identified by the containment path
|
|
28
|
+
originating from an explicit EntitySet. This enhancement has an observable effect only in structured format with containment
|
|
29
|
+
turned on.
|
|
30
|
+
+ Support for scales `variable` and `floating`:
|
|
31
|
+
+ V4: `variable` and `floating` are rendered as `Scale="variable"`. Since V4 does not support `floating`, it is aproximated as `variable`.
|
|
32
|
+
+ V2: `variable` and `floating` are announced via property annotation `sap:variable-scale="true"`
|
|
33
|
+
|
|
34
|
+
- to.sql/hdi/hdbcds:
|
|
35
|
+
+ Reject scale `floating` and `variable`.
|
|
36
|
+
+ Reject arbitrary `$user` or `$session` paths that cannot be translated to valid SQL.
|
|
37
|
+
+ Following a valid `exists`, further `exists` can be used inside of the filter-expression: `exists assoc[exists another[1=1]]`
|
|
38
|
+
+ `exists` can now be followed by more than one association step.
|
|
39
|
+
`exists assoc.anotherassoc.moreassoc` is semantically equivalent to `exists assoc[exists anotherassoc[exists moreassoc]]`
|
|
40
|
+
|
|
41
|
+
### Removed
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- to.odata: Inform when overwriting draft action annotations like @Common.DraftRoot.ActivationAction.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
## Version 2.9.0 - 2021-10-15
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
|
|
53
|
+
- to.edm(x): Raise `odata-spec-violation-type` to a downgradable error.
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
|
|
57
|
+
- to.edm(x):
|
|
58
|
+
+ Fix a bug in annotation propagation to foreign keys.
|
|
59
|
+
+ Don't render annotations for not rendered stream element in V2.
|
|
60
|
+
- to.hdi:
|
|
61
|
+
+ for naming mode "hdbcds" and "quoted" parameter definitions are not quoted anymore.
|
|
62
|
+
- to.hdi/sql/hdbcds:
|
|
63
|
+
+ Correctly handle explicit and implicit alias during flattening.
|
|
64
|
+
+ Raise an error for `@odata.draft.enabled` artifacts with elements without types - instead of crashing with internal assertions.
|
|
65
|
+
|
|
66
|
+
## Version 2.8.0 - 2021-10-07
|
|
67
|
+
|
|
68
|
+
### Added
|
|
69
|
+
|
|
70
|
+
- Allow defining unmanaged associations in anonymous aspects of compositions.
|
|
71
|
+
- Enable extensions of anonymous aspects for managed compositions of aspects.
|
|
72
|
+
- When the option `addTextsLanguageAssoc` is set to true and
|
|
73
|
+
the model contains an entity `sap.common.Languages` with an element `code`,
|
|
74
|
+
all generated texts entities additionally contain an element `language`
|
|
75
|
+
which is an association to `sap.common.Languages` using element `local`.
|
|
76
|
+
- for.odata:
|
|
77
|
+
+ In `--odata-format=flat`, structured view parameters are flattened like elements.
|
|
78
|
+
- to.hdbcds
|
|
79
|
+
+ Use "smart quotes" for naming mode "plain" - automatically quote identifier which are reserved keywords or non-regular.
|
|
80
|
+
|
|
81
|
+
### Changed
|
|
82
|
+
|
|
83
|
+
- for.odata:
|
|
84
|
+
+ In `--data-format=structured`, anonymous sub elements of primary keys and parameters are set to `notNull:true`,
|
|
85
|
+
an existing `notNull` attribute is _not_ overwritten. Referred named types are _not_ modified.
|
|
86
|
+
- to.edm(x):
|
|
87
|
+
+ Improve specification violation checks of (nested) keys:
|
|
88
|
+
+ All (sub-)elements must be `Nullable: false` (error).
|
|
89
|
+
+ Must represent a single value (error).
|
|
90
|
+
+ In V4 must be a specification compliant Edm.PrimitiveType (warning).
|
|
91
|
+
- to.hdi/hdbcds/sql: $user.\<xy\> now has \<xy\> added as alias - "$user.\<xy\> as \<xy\>"
|
|
92
|
+
|
|
93
|
+
### Fixed
|
|
94
|
+
|
|
95
|
+
- Properly generate auto-exposed entities for associations in parameters.
|
|
96
|
+
- Correctly apply extensions to anonymous array item types.
|
|
97
|
+
- Correctly apply/render annotations to anonymous action return types.
|
|
98
|
+
- With CSN flavor `plain` (`gensrc`), correctly render annotations on elements
|
|
99
|
+
of referred structure types as `annotate` statements in the CSN's `extensions` property.
|
|
100
|
+
- to.cdl:
|
|
101
|
+
+ Correctly render extensions on array item types
|
|
102
|
+
+ Correctly render annotations on action return types
|
|
103
|
+
- to/for: Correctly handle CSN input where the prototype of objects is not the "default"
|
|
104
|
+
- to.hdi:
|
|
105
|
+
+ for naming mode "hdbcds" and "quoted" parameter definitions are now quoted.
|
|
106
|
+
+ for naming mode "plain", smart quotation is applied to parameter definitions if they are reserved words.
|
|
107
|
+
- to.hdi/hdbcds/sql:
|
|
108
|
+
+ Ensure that cdl-style casts to localized types do not lose their localized property
|
|
109
|
+
+ Fix a small memory leak during rendering of SQL/HDBCDS.
|
|
110
|
+
- to.edm(x): Remove ambiguous `Partner` attribute from `NavigationProperty`. A forward association referred
|
|
111
|
+
to by multiple backlinks (`$self` comparisons) is no longer partner to an arbitrary backlink.
|
|
112
|
+
|
|
113
|
+
## Version 2.7.0 - 2021-09-22
|
|
114
|
+
|
|
115
|
+
### Added
|
|
116
|
+
|
|
117
|
+
- to.hdi.migration:
|
|
118
|
+
+ Support changes to HANA comments.
|
|
119
|
+
|
|
120
|
+
### Changed
|
|
121
|
+
|
|
122
|
+
- Updated OData vocabularies 'Common', 'Core'
|
|
123
|
+
|
|
124
|
+
### Fixed
|
|
125
|
+
|
|
126
|
+
- Fix memory issue: do not keep reference to last-compiled model.
|
|
127
|
+
- Fix dump which occured when trying to report that the user has defined an element to be both `key` and `localized` if
|
|
128
|
+
`localized` was inherited via the provided type, or in the generated entity for a managed composition of aspect.
|
|
129
|
+
- Properly auto-expose targets of associations in parameters and `many`.
|
|
130
|
+
- for.Odata:
|
|
131
|
+
+ Fix handling of annotation `@cds.odata.valuelist` in conjunction with associations in structures using flat-mode and sqlMapping set to plain.
|
|
132
|
+
+ Set correctly the $localized property in the OData backend resulting CSN for artifacts that have localized convenience views.
|
|
133
|
+
- to.edm(x):
|
|
134
|
+
+ Fix rendering of structured referential constraints and nested partnerships in combination with `$self` comparisons.
|
|
135
|
+
+ Fix merging of `@Capabilities` annotations while transforming them into `NavigationCapabilities` from the containee into the container.
|
|
136
|
+
- to.sql/hdi/hdbcds:
|
|
137
|
+
+ Fix a bug in Association to Join translation in multi-level association redirection in combination with `$self`.
|
|
138
|
+
+ Correctly flatten paths with filters or parameters.
|
|
139
|
+
+ Improve error message in case of invalid `exists`.
|
|
140
|
+
|
|
141
|
+
## Version 2.6.2 - 2021-08-26
|
|
142
|
+
|
|
143
|
+
### Fixed
|
|
144
|
+
|
|
145
|
+
- to.sql/hdi/hdbcds/edm(x)/for.odata: Correctly handle tuple expansion in subqueries of Unions.
|
|
146
|
+
|
|
147
|
+
## Version 2.6.0 - 2021-08-23
|
|
148
|
+
|
|
149
|
+
### Added
|
|
150
|
+
|
|
151
|
+
- Support managed associations without foreign keys. Associations targeting a definition without primary keys or with an
|
|
152
|
+
explicit empty foreign key tuple or with empty structured elements as foreign keys and their corresponding `$self`
|
|
153
|
+
comparisons do not describe the relationship between the source and the target entity.
|
|
154
|
+
These associations can be used to establish API navigations but cannot be used to access elements in the target
|
|
155
|
+
entity as they cannot be transformed into a valid JOIN expression.
|
|
156
|
+
Consequently, these associations are not added to the `WITH ASSOCIATIONS` clause or forwarded to HANA CDS.
|
|
157
|
+
- to.sql/hdi/hdbcds/edm(x)/for.odata: Structure/managed association comparisons (tuple comparisons) are now
|
|
158
|
+
also expanded in infix filters, all expressions and all on-conditions.
|
|
159
|
+
- to.hdbcds: Better locations for messages - mostly concerning keywords and duplicates
|
|
160
|
+
|
|
161
|
+
### Changed
|
|
162
|
+
|
|
163
|
+
- to.sql/hdi/hdbcds: Invalid (i.e. not expandable) usage of structures is now checked - an error is raised
|
|
164
|
+
|
|
165
|
+
### Removed
|
|
166
|
+
|
|
167
|
+
- The internal non-enumerable CSN property `$env` has been removed from the compiled CSN.
|
|
168
|
+
|
|
169
|
+
### Fixed
|
|
170
|
+
|
|
171
|
+
- Make `;` optional before `}` in all circumstances (was not the case with `many`).
|
|
172
|
+
- to.sql/hdi/hdbcds/edm(x): More graceful handling of CSN input where associations do not have `keys` or an `on`-condition
|
|
173
|
+
|
|
174
|
+
## Version 2.5.2 - 2021-08-10
|
|
175
|
+
|
|
176
|
+
### Fixed
|
|
177
|
+
|
|
178
|
+
- to.hdbcds: Fixed a bug introduced with 2.5.0 that caused virtual elements to be rendered in views.
|
|
179
|
+
|
|
180
|
+
## Version 2.5.0 - 2021-07-28
|
|
181
|
+
|
|
182
|
+
### Added
|
|
183
|
+
|
|
184
|
+
- Allow to extend existing array annotation values via the ellipsis operator `...`.
|
|
185
|
+
An ellipsis may appear exactly once at an arbitrary position in the top level array
|
|
186
|
+
of an `annotate` directive. Only array values can be merged into arrays and unapplied
|
|
187
|
+
ellipses are removed from the final array value. Annotation layering rules remain unaffected.
|
|
188
|
+
- to.sql/hdi/hdbcds:
|
|
189
|
+
+ Doc comments are translated into HANA comments (or into `@Comment` annotation for `to.hdbcds`).
|
|
190
|
+
Such comments are possible on entities, views, elements of entities and `to.hdbcds` also supports comments on view columns.
|
|
191
|
+
Generation can be disabled via option `disableHanaComments`. Entites/views (and their elements/columns)
|
|
192
|
+
annotated with `@cds.persistence.journal` for `to.hdi`/`to.sql` will not have comments rendered.
|
|
193
|
+
+ Generation of temporal `WHERE` clause can be suppressed by annotating the `validFrom`/`validTo` elements of the projection with `false` or `null`.
|
|
194
|
+
- to.sql/hdi/hdbcds/edm(x)/for.odata: Structure/managed association comparisons (tuple comparisons) are now
|
|
195
|
+
also expanded in `WHERE` and `HAVING` - this was previously only supported in on-conditions.
|
|
196
|
+
- `cdsc` now internally uses SNAPI.
|
|
197
|
+
- to.hdi.migration:
|
|
198
|
+
+ Validate that the two supplied CSNs are compatible.
|
|
199
|
+
+ Improve delta-mechanism to not render superflous [ALTER|DROP|ADD] statements for unchanged SQL.
|
|
200
|
+
|
|
201
|
+
### Changed
|
|
202
|
+
|
|
203
|
+
- If the first source provided to the compile command has a `$sources` property
|
|
204
|
+
(whether enumerable or not) which is an array of strings,
|
|
205
|
+
use that instead of calculating one.
|
|
206
|
+
- Updated OData vocabularies 'Aggregation', 'Analytics', 'Authorization', 'Capabilities',
|
|
207
|
+
'CodeList', 'Common', 'Communication', 'Core', 'Graph', 'HTML5', 'Measures', 'ODM', 'PersonalData',
|
|
208
|
+
'Repeatability', 'Session', 'UI', 'Validation'
|
|
209
|
+
|
|
210
|
+
### Removed
|
|
211
|
+
|
|
212
|
+
- Removed internal property `$viaTransform` from CSN produced by OData/HANA transformation
|
|
213
|
+
|
|
214
|
+
### Fixed
|
|
215
|
+
|
|
216
|
+
- Remove warnings 'Ignoring annotation “@odata.draft.enabled” as the artifact is not part of a service'
|
|
217
|
+
and 'Ignoring draft node for composition target ... because it is not part of a service'
|
|
218
|
+
- Doc comments are no longer ignored after enum values and on view columns in parseCdl mode.
|
|
219
|
+
- to.cdl:
|
|
220
|
+
+ Doc comments for enum values are correctly rendered.
|
|
221
|
+
+ Enum value and doc comments are now correctly rendered if the enum is called `doc`.
|
|
222
|
+
+ Doc comments at type references are correctly rendered.
|
|
223
|
+
+ Empty doc comments are correctly rendered and not left out.
|
|
224
|
+
+ Doc comments on view columns are correctly rendered.
|
|
225
|
+
- to.edm(x):
|
|
226
|
+
+ OData V2: Ignore `@odata.singleton`.
|
|
227
|
+
+ OData V4: Do not render an `edm:NavigationPropertyBinding` to a singleton if the association has
|
|
228
|
+
cardinality 'to-many'.
|
|
229
|
+
- forOData:
|
|
230
|
+
+ Fix automatic renaming of shortcut annotation (eg. `@label`) with value `null`.
|
|
231
|
+
- CSN parser:
|
|
232
|
+
+ Empty doc comments are correctly parsed and not complained about.
|
|
233
|
+
|
|
10
234
|
## Version 2.4.4 - 2021-07-02
|
|
11
235
|
|
|
12
236
|
### Fixed
|
|
13
237
|
|
|
14
238
|
- Do not remove parentheses around single literals and references on the right-hand side of an `in` and `not in` operator.
|
|
15
|
-
of an `in` and `not in` operator.
|
|
16
239
|
|
|
17
240
|
## Version 2.4.2 - 2021-07-01
|
|
18
241
|
|
|
@@ -113,6 +336,11 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
113
336
|
caused regressions in mocking scenarios. With option `--odata-v2-partial-constr` partial constraint generation
|
|
114
337
|
can be reactivated. A 'odata-spec-violation-constraints' warning is raised.
|
|
115
338
|
|
|
339
|
+
### 2.5.0 Addendum to Changed
|
|
340
|
+
|
|
341
|
+
- Replace outdated option `length` with `defaultStringLength` which is usable in `for.*` and `to.*` APIs.
|
|
342
|
+
|
|
343
|
+
|
|
116
344
|
## Version 2.2.4 - 2021-05-06
|
|
117
345
|
|
|
118
346
|
No changes compared to Version 2.2.2; fixes latest NPM tag
|
|
@@ -419,6 +647,18 @@ synchronously.
|
|
|
419
647
|
- to.hdi.migration: Don't generate `ALTER` for type change from association to composition or vice versa (if the rest stays the same),
|
|
420
648
|
as the resulting SQL is identical.
|
|
421
649
|
|
|
650
|
+
## Version 1.50.10 - 2021-07-30
|
|
651
|
+
|
|
652
|
+
### Fixed
|
|
653
|
+
|
|
654
|
+
- to.hdi.migration: Check for incompatible CSN versions to avoid wrongly generated ALTER|DROP|ADD statements.
|
|
655
|
+
|
|
656
|
+
## Version 1.50.8 - 2021-07-01
|
|
657
|
+
|
|
658
|
+
### Fixed
|
|
659
|
+
|
|
660
|
+
- to.hdi.migration: Don't generate `ALTER` for type change from association to composition or vice versa (if the rest stays the same), as the resulting SQL is identical.
|
|
661
|
+
|
|
422
662
|
## Version 1.50.6 - 2021-05-05
|
|
423
663
|
|
|
424
664
|
### Fixed
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["../.eslintrc-ydkjsi.json"],
|
|
3
|
+
"rules": {
|
|
4
|
+
"prefer-const": "error",
|
|
5
|
+
"quotes": ["error", "single", "avoid-escape"],
|
|
6
|
+
"prefer-template": "error",
|
|
7
|
+
"no-trailing-spaces": "error",
|
|
8
|
+
"template-curly-spacing": ["error", "never"],
|
|
9
|
+
"max-len": "off",
|
|
10
|
+
"no-console": "off",
|
|
11
|
+
"no-process-exit": "off",
|
|
12
|
+
"camelcase": "off",
|
|
13
|
+
"radix": "off",
|
|
14
|
+
// should probably be on
|
|
15
|
+
"no-shadow": "off"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
//
|
|
21
21
|
// Note that you need to update the path to this script in the commands above.
|
|
22
22
|
//
|
|
23
|
+
|
|
23
24
|
'use strict';
|
|
24
25
|
|
|
25
26
|
const parseLanguage = require('../lib/language/antlrParser');
|
|
@@ -30,7 +31,7 @@ const path = require('path');
|
|
|
30
31
|
const cliArgs = process.argv.slice(2);
|
|
31
32
|
const filename = cliArgs[0];
|
|
32
33
|
|
|
33
|
-
if (cliArgs.length
|
|
34
|
+
if (cliArgs.length !== 1)
|
|
34
35
|
exitError(`Expected exactly one argument, ${cliArgs.length} given`);
|
|
35
36
|
|
|
36
37
|
if (!filename)
|
|
@@ -58,7 +59,7 @@ function modernizeIdentifierStyle(source, filename) {
|
|
|
58
59
|
// To avoid spam, only report errors.
|
|
59
60
|
// Users should use the compiler to get all messages.
|
|
60
61
|
const errors = options.messages
|
|
61
|
-
|
|
62
|
+
.filter(msg => (msg.severity === 'Error' && msg.messageId !== 'syntax-deprecated-ident'));
|
|
62
63
|
if (errors.length > 0) {
|
|
63
64
|
errors.forEach((msg) => {
|
|
64
65
|
console.error(msg.toString());
|
|
@@ -69,7 +70,7 @@ function modernizeIdentifierStyle(source, filename) {
|
|
|
69
70
|
|
|
70
71
|
let currentOffset = 0;
|
|
71
72
|
|
|
72
|
-
const tokens = ast.tokenStream
|
|
73
|
+
const { tokens } = ast.tokenStream;
|
|
73
74
|
for (const token of tokens) {
|
|
74
75
|
if (token.type === ast.tokenStream.Identifier && token.text.startsWith('"'))
|
|
75
76
|
updateIdent(token);
|
|
@@ -83,10 +84,10 @@ function modernizeIdentifierStyle(source, filename) {
|
|
|
83
84
|
const newIdentText = toNewIdentStyle(identToken.text);
|
|
84
85
|
|
|
85
86
|
if (!identToken.stop)
|
|
86
|
-
throw new Error(`INTERNAL ERROR: Identifier at ${
|
|
87
|
+
throw new Error(`INTERNAL ERROR: Identifier at ${identToken.start} has no end!`);
|
|
87
88
|
|
|
88
89
|
const start = identToken.start + currentOffset;
|
|
89
|
-
const end =
|
|
90
|
+
const end = identToken.stop + currentOffset + 1; // end points at the position *before* the character
|
|
90
91
|
|
|
91
92
|
source = replaceSliceInSource(source, start, end, newIdentText);
|
|
92
93
|
|
|
@@ -100,7 +101,7 @@ function modernizeIdentifierStyle(source, filename) {
|
|
|
100
101
|
ident = ident.replace(/""/g, '"');
|
|
101
102
|
ident = ident.replace(/]/g, ']]');
|
|
102
103
|
|
|
103
|
-
return `![${
|
|
104
|
+
return `![${ident}]`;
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
@@ -129,6 +130,6 @@ function exitError(msg) {
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
function usage() {
|
|
132
|
-
console.error('')
|
|
133
|
+
console.error('');
|
|
133
134
|
console.error(`usage: ${path.basename(process.argv[1])} <filename>`);
|
|
134
135
|
}
|