@servicenow/sdk-build-plugins 3.0.2 → 4.0.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/dist/acl-plugin.d.ts +19 -0
- package/dist/acl-plugin.js +210 -0
- package/dist/acl-plugin.js.map +1 -0
- package/dist/application-menu-plugin.d.ts +18 -0
- package/dist/application-menu-plugin.js +104 -0
- package/dist/application-menu-plugin.js.map +1 -0
- package/dist/arrow-function-plugin.d.ts +16 -0
- package/dist/arrow-function-plugin.js +107 -0
- package/dist/arrow-function-plugin.js.map +1 -0
- package/dist/atf/step-configs.d.ts +37 -0
- package/dist/atf/step-configs.js +2236 -0
- package/dist/atf/step-configs.js.map +1 -0
- package/dist/atf/test-plugin.d.ts +4 -0
- package/dist/atf/test-plugin.js +591 -0
- package/dist/atf/test-plugin.js.map +1 -0
- package/dist/basic-syntax-plugin.d.ts +2 -0
- package/dist/basic-syntax-plugin.js +636 -0
- package/dist/basic-syntax-plugin.js.map +1 -0
- package/dist/business-rule-plugin.d.ts +3 -0
- package/dist/business-rule-plugin.js +205 -0
- package/dist/business-rule-plugin.js.map +1 -0
- package/dist/call-expression-plugin.d.ts +2 -0
- package/dist/call-expression-plugin.js +175 -0
- package/dist/call-expression-plugin.js.map +1 -0
- package/dist/client-script-plugin.d.ts +29 -0
- package/dist/client-script-plugin.js +157 -0
- package/dist/client-script-plugin.js.map +1 -0
- package/dist/column/column-helper.d.ts +12 -0
- package/dist/column/column-helper.js +84 -0
- package/dist/column/column-helper.js.map +1 -0
- package/dist/column/column-to-record.d.ts +3 -0
- package/dist/column/column-to-record.js +105 -0
- package/dist/column/column-to-record.js.map +1 -0
- package/dist/column-plugin.d.ts +8 -0
- package/dist/column-plugin.js +453 -0
- package/dist/column-plugin.js.map +1 -0
- package/dist/cross-scope-privilege-plugin.d.ts +15 -0
- package/dist/cross-scope-privilege-plugin.js +82 -0
- package/dist/cross-scope-privilege-plugin.js.map +1 -0
- package/dist/html-import-plugin.d.ts +2 -0
- package/dist/html-import-plugin.js +72 -0
- package/dist/html-import-plugin.js.map +1 -0
- package/dist/index.d.ts +37 -21
- package/dist/index.js +40 -45
- package/dist/index.js.map +1 -1
- package/dist/json-plugin.d.ts +15 -0
- package/dist/json-plugin.js +104 -0
- package/dist/json-plugin.js.map +1 -0
- package/dist/list-plugin.d.ts +2 -0
- package/dist/list-plugin.js +191 -0
- package/dist/list-plugin.js.map +1 -0
- package/dist/now-config-plugin.d.ts +4 -0
- package/dist/now-config-plugin.js +154 -0
- package/dist/now-config-plugin.js.map +1 -0
- package/dist/now-id-plugin.d.ts +11 -0
- package/dist/now-id-plugin.js +71 -0
- package/dist/now-id-plugin.js.map +1 -0
- package/dist/now-include-plugin.d.ts +16 -0
- package/dist/now-include-plugin.js +118 -0
- package/dist/now-include-plugin.js.map +1 -0
- package/dist/now-ref-plugin.d.ts +2 -0
- package/dist/now-ref-plugin.js +43 -0
- package/dist/now-ref-plugin.js.map +1 -0
- package/dist/now-unresolved-plugin.d.ts +2 -0
- package/dist/now-unresolved-plugin.js +32 -0
- package/dist/now-unresolved-plugin.js.map +1 -0
- package/dist/package-json-plugin.d.ts +2 -0
- package/dist/package-json-plugin.js +70 -0
- package/dist/package-json-plugin.js.map +1 -0
- package/dist/property-plugin.d.ts +2 -0
- package/dist/property-plugin.js +105 -0
- package/dist/property-plugin.js.map +1 -0
- package/dist/record-plugin.d.ts +43 -0
- package/dist/record-plugin.js +147 -0
- package/dist/record-plugin.js.map +1 -0
- package/dist/repack/index.d.ts +1 -0
- package/dist/repack/index.js +10 -2
- package/dist/repack/index.js.map +1 -1
- package/dist/repack/lint/Rules.d.ts +1 -1
- package/dist/repack/lint/Rules.js +7 -3
- package/dist/repack/lint/Rules.js.map +1 -1
- package/dist/repack/lint/index.js +1 -1
- package/dist/rest-api-plugin.d.ts +2 -0
- package/dist/rest-api-plugin.js +469 -0
- package/dist/rest-api-plugin.js.map +1 -0
- package/dist/role-plugin.d.ts +2 -0
- package/dist/role-plugin.js +117 -0
- package/dist/role-plugin.js.map +1 -0
- package/dist/script-action-plugin.d.ts +2 -0
- package/dist/script-action-plugin.js +62 -0
- package/dist/script-action-plugin.js.map +1 -0
- package/dist/script-include-plugin.d.ts +2 -0
- package/dist/script-include-plugin.js +102 -0
- package/dist/script-include-plugin.js.map +1 -0
- package/dist/server-module-plugin/index.d.ts +14 -0
- package/dist/server-module-plugin/index.js +378 -0
- package/dist/server-module-plugin/index.js.map +1 -0
- package/dist/server-module-plugin/sbom-builder.d.ts +45 -0
- package/dist/server-module-plugin/sbom-builder.js +179 -0
- package/dist/server-module-plugin/sbom-builder.js.map +1 -0
- package/dist/service-portal/angular-provider-plugin.d.ts +2 -0
- package/dist/service-portal/angular-provider-plugin.js +78 -0
- package/dist/service-portal/angular-provider-plugin.js.map +1 -0
- package/dist/service-portal/dependency-plugin.d.ts +2 -0
- package/dist/service-portal/dependency-plugin.js +235 -0
- package/dist/service-portal/dependency-plugin.js.map +1 -0
- package/dist/service-portal/widget-plugin.d.ts +6 -0
- package/dist/service-portal/widget-plugin.js +230 -0
- package/dist/service-portal/widget-plugin.js.map +1 -0
- package/dist/static-content-plugin.d.ts +2 -0
- package/dist/static-content-plugin.js +272 -0
- package/dist/static-content-plugin.js.map +1 -0
- package/dist/table-plugin.d.ts +3 -0
- package/dist/table-plugin.js +1324 -0
- package/dist/table-plugin.js.map +1 -0
- package/dist/ui-action-plugin.d.ts +2 -0
- package/dist/ui-action-plugin.js +291 -0
- package/dist/ui-action-plugin.js.map +1 -0
- package/dist/ui-page-plugin.d.ts +2 -0
- package/dist/ui-page-plugin.js +165 -0
- package/dist/ui-page-plugin.js.map +1 -0
- package/dist/user-preference-plugin.d.ts +15 -0
- package/dist/user-preference-plugin.js +63 -0
- package/dist/user-preference-plugin.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +72 -0
- package/dist/utils.js.map +1 -0
- package/dist/view-plugin.d.ts +2 -0
- package/dist/view-plugin.js +45 -0
- package/dist/view-plugin.js.map +1 -0
- package/package.json +17 -13
- package/src/acl-plugin.ts +256 -0
- package/src/application-menu-plugin.ts +109 -0
- package/src/arrow-function-plugin.ts +127 -0
- package/src/atf/step-configs.ts +2284 -0
- package/src/atf/test-plugin.ts +728 -0
- package/src/basic-syntax-plugin.ts +729 -0
- package/src/business-rule-plugin.ts +266 -0
- package/src/call-expression-plugin.ts +202 -0
- package/src/client-script-plugin.ts +170 -0
- package/src/column/column-helper.ts +119 -0
- package/src/column/column-to-record.ts +131 -0
- package/src/column-plugin.ts +506 -0
- package/src/cross-scope-privilege-plugin.ts +82 -0
- package/src/html-import-plugin.ts +79 -0
- package/src/index.ts +39 -21
- package/src/json-plugin.ts +128 -0
- package/src/list-plugin.ts +222 -0
- package/src/now-config-plugin.ts +194 -0
- package/src/now-id-plugin.ts +78 -0
- package/src/now-include-plugin.ts +140 -0
- package/src/now-ref-plugin.ts +48 -0
- package/src/now-unresolved-plugin.ts +30 -0
- package/src/package-json-plugin.ts +87 -0
- package/src/property-plugin.ts +118 -0
- package/src/record-plugin.ts +171 -0
- package/src/repack/index.ts +10 -1
- package/src/repack/lint/Rules.ts +5 -4
- package/src/repack/lint/index.ts +1 -1
- package/src/rest-api-plugin.ts +651 -0
- package/src/role-plugin.ts +128 -0
- package/src/script-action-plugin.ts +63 -0
- package/src/script-include-plugin.ts +110 -0
- package/src/server-module-plugin/index.ts +470 -0
- package/src/server-module-plugin/sbom-builder.ts +183 -0
- package/src/service-portal/angular-provider-plugin.ts +83 -0
- package/src/service-portal/dependency-plugin.ts +284 -0
- package/src/service-portal/widget-plugin.ts +263 -0
- package/src/static-content-plugin.ts +254 -0
- package/src/table-plugin.ts +1698 -0
- package/src/ui-action-plugin.ts +324 -0
- package/src/ui-page-plugin.ts +168 -0
- package/src/user-preference-plugin.ts +62 -0
- package/src/utils.ts +69 -0
- package/src/view-plugin.ts +46 -0
- package/dist/AttachmentPlugin.d.ts +0 -254
- package/dist/AttachmentPlugin.js +0 -220
- package/dist/AttachmentPlugin.js.map +0 -1
- package/dist/BusinessRulePlugin.d.ts +0 -30
- package/dist/BusinessRulePlugin.js +0 -149
- package/dist/BusinessRulePlugin.js.map +0 -1
- package/dist/CrossScopePrivilegePlugin.d.ts +0 -35
- package/dist/CrossScopePrivilegePlugin.js +0 -80
- package/dist/CrossScopePrivilegePlugin.js.map +0 -1
- package/dist/DefaultPlugin.d.ts +0 -86
- package/dist/DefaultPlugin.js +0 -226
- package/dist/DefaultPlugin.js.map +0 -1
- package/dist/HtmlTemplatePlugin.d.ts +0 -21
- package/dist/HtmlTemplatePlugin.js +0 -29
- package/dist/HtmlTemplatePlugin.js.map +0 -1
- package/dist/IdPlugin.d.ts +0 -28
- package/dist/IdPlugin.js +0 -68
- package/dist/IdPlugin.js.map +0 -1
- package/dist/IncludePlugin.d.ts +0 -34
- package/dist/IncludePlugin.js +0 -155
- package/dist/IncludePlugin.js.map +0 -1
- package/dist/JsonPlugin.d.ts +0 -28
- package/dist/JsonPlugin.js +0 -69
- package/dist/JsonPlugin.js.map +0 -1
- package/dist/ListPlugin.d.ts +0 -93
- package/dist/ListPlugin.js +0 -456
- package/dist/ListPlugin.js.map +0 -1
- package/dist/NowConfigPlugin.d.ts +0 -45
- package/dist/NowConfigPlugin.js +0 -64
- package/dist/NowConfigPlugin.js.map +0 -1
- package/dist/PackageJsonPlugin.d.ts +0 -34
- package/dist/PackageJsonPlugin.js +0 -63
- package/dist/PackageJsonPlugin.js.map +0 -1
- package/dist/PropertyPlugin.d.ts +0 -51
- package/dist/PropertyPlugin.js +0 -181
- package/dist/PropertyPlugin.js.map +0 -1
- package/dist/ScriptTemplatePlugin.d.ts +0 -13
- package/dist/ScriptTemplatePlugin.js +0 -55
- package/dist/ScriptTemplatePlugin.js.map +0 -1
- package/dist/ServerModulePlugin.d.ts +0 -75
- package/dist/ServerModulePlugin.js +0 -368
- package/dist/ServerModulePlugin.js.map +0 -1
- package/dist/UserPreferencePlugin.d.ts +0 -19
- package/dist/UserPreferencePlugin.js +0 -32
- package/dist/UserPreferencePlugin.js.map +0 -1
- package/dist/aclAndRole/AclPlugin.d.ts +0 -82
- package/dist/aclAndRole/AclPlugin.js +0 -262
- package/dist/aclAndRole/AclPlugin.js.map +0 -1
- package/dist/aclAndRole/RolePlugin.d.ts +0 -66
- package/dist/aclAndRole/RolePlugin.js +0 -179
- package/dist/aclAndRole/RolePlugin.js.map +0 -1
- package/dist/aclAndRole/Util.d.ts +0 -3
- package/dist/aclAndRole/Util.js +0 -90
- package/dist/aclAndRole/Util.js.map +0 -1
- package/dist/app/ApplicationMenuPlugin.d.ts +0 -34
- package/dist/app/ApplicationMenuPlugin.js +0 -112
- package/dist/app/ApplicationMenuPlugin.js.map +0 -1
- package/dist/db/ColumnPlugins.d.ts +0 -750
- package/dist/db/ColumnPlugins.js +0 -114
- package/dist/db/ColumnPlugins.js.map +0 -1
- package/dist/db/DBUtils.d.ts +0 -2
- package/dist/db/DBUtils.js +0 -27
- package/dist/db/DBUtils.js.map +0 -1
- package/dist/db/DocumentationPlugin.d.ts +0 -67
- package/dist/db/DocumentationPlugin.js +0 -258
- package/dist/db/DocumentationPlugin.js.map +0 -1
- package/dist/db/LicensingPlugin.d.ts +0 -60
- package/dist/db/LicensingPlugin.js +0 -117
- package/dist/db/LicensingPlugin.js.map +0 -1
- package/dist/db/RecordPlugin.d.ts +0 -133
- package/dist/db/RecordPlugin.js +0 -337
- package/dist/db/RecordPlugin.js.map +0 -1
- package/dist/db/TablePlugin.d.ts +0 -231
- package/dist/db/TablePlugin.js +0 -1628
- package/dist/db/TablePlugin.js.map +0 -1
- package/dist/db/index.d.ts +0 -6
- package/dist/db/index.js +0 -32
- package/dist/db/index.js.map +0 -1
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +0 -10
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +0 -373
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +0 -13
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js +0 -177
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +0 -81
- package/dist/scriptedRESTAPI/RestApiPlugin.js +0 -345
- package/dist/scriptedRESTAPI/RestApiPlugin.js.map +0 -1
- package/dist/scriptedRESTAPI/RestSchemaUtils.d.ts +0 -190
- package/dist/scriptedRESTAPI/RestSchemaUtils.js +0 -53
- package/dist/scriptedRESTAPI/RestSchemaUtils.js.map +0 -1
- package/dist/scriptedRESTAPI/RestUtils.d.ts +0 -69
- package/dist/scriptedRESTAPI/RestUtils.js +0 -497
- package/dist/scriptedRESTAPI/RestUtils.js.map +0 -1
- package/dist/scripts/ClientScriptPlugin.d.ts +0 -64
- package/dist/scripts/ClientScriptPlugin.js +0 -170
- package/dist/scripts/ClientScriptPlugin.js.map +0 -1
- package/dist/scripts/scriptUtils.d.ts +0 -1
- package/dist/scripts/scriptUtils.js +0 -9
- package/dist/scripts/scriptUtils.js.map +0 -1
- package/dist/uxf/ExperiencePlugin.d.ts +0 -45
- package/dist/uxf/ExperiencePlugin.js +0 -61
- package/dist/uxf/ExperiencePlugin.js.map +0 -1
- package/dist/uxf/RoutesPlugin.d.ts +0 -29
- package/dist/uxf/RoutesPlugin.js +0 -181
- package/dist/uxf/RoutesPlugin.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/cleanUxValue.d.ts +0 -4
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js +0 -65
- package/dist/uxf/UxfFormulaParser/cleanUxValue.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/api.d.ts +0 -189
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js +0 -158
- package/dist/uxf/UxfFormulaParser/grammerParser/api.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.d.ts +0 -13
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -604
- package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.d.ts +0 -12
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
- package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.d.ts +0 -31
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -64
- package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/index.d.ts +0 -3
- package/dist/uxf/UxfFormulaParser/index.js +0 -11
- package/dist/uxf/UxfFormulaParser/index.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/parser.d.ts +0 -8
- package/dist/uxf/UxfFormulaParser/parser.js +0 -87
- package/dist/uxf/UxfFormulaParser/parser.js.map +0 -1
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.d.ts +0 -8
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js +0 -17
- package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js.map +0 -1
- package/dist/uxf/constants.d.ts +0 -2
- package/dist/uxf/constants.js +0 -8
- package/dist/uxf/constants.js.map +0 -1
- package/dist/uxf/index.d.ts +0 -2
- package/dist/uxf/index.js +0 -11
- package/dist/uxf/index.js.map +0 -1
- package/dist/uxf/tectonicIdGenerator.d.ts +0 -12
- package/dist/uxf/tectonicIdGenerator.js +0 -79
- package/dist/uxf/tectonicIdGenerator.js.map +0 -1
- package/src/AttachmentPlugin.ts +0 -268
- package/src/BusinessRulePlugin.ts +0 -238
- package/src/CrossScopePrivilegePlugin.ts +0 -115
- package/src/DefaultPlugin.ts +0 -288
- package/src/HtmlTemplatePlugin.ts +0 -31
- package/src/IdPlugin.ts +0 -74
- package/src/IncludePlugin.ts +0 -206
- package/src/JsonPlugin.ts +0 -76
- package/src/ListPlugin.ts +0 -570
- package/src/NowConfigPlugin.ts +0 -69
- package/src/PackageJsonPlugin.ts +0 -68
- package/src/PropertyPlugin.ts +0 -237
- package/src/ScriptTemplatePlugin.ts +0 -53
- package/src/ServerModulePlugin.ts +0 -480
- package/src/UserPreferencePlugin.ts +0 -45
- package/src/aclAndRole/AclPlugin.ts +0 -420
- package/src/aclAndRole/RolePlugin.ts +0 -254
- package/src/aclAndRole/Util.ts +0 -113
- package/src/app/ApplicationMenuPlugin.ts +0 -165
- package/src/db/ColumnPlugins.ts +0 -114
- package/src/db/DBUtils.ts +0 -36
- package/src/db/DocumentationPlugin.ts +0 -316
- package/src/db/LicensingPlugin.ts +0 -138
- package/src/db/RecordPlugin.ts +0 -459
- package/src/db/TablePlugin.ts +0 -2070
- package/src/db/index.ts +0 -6
- package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +0 -419
- package/src/scriptedRESTAPI/RESTSerializationUtils.ts +0 -228
- package/src/scriptedRESTAPI/RestApiPlugin.ts +0 -469
- package/src/scriptedRESTAPI/RestSchemaUtils.ts +0 -72
- package/src/scriptedRESTAPI/RestUtils.ts +0 -569
- package/src/scripts/ClientScriptPlugin.ts +0 -257
- package/src/scripts/scriptUtils.ts +0 -5
- package/src/uxf/ExperiencePlugin.ts +0 -67
- package/src/uxf/RoutesPlugin.ts +0 -211
- package/src/uxf/UxfFormulaParser/cleanUxValue.ts +0 -73
- package/src/uxf/UxfFormulaParser/grammerParser/api.js +0 -166
- package/src/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -606
- package/src/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
- package/src/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -65
- package/src/uxf/UxfFormulaParser/index.ts +0 -4
- package/src/uxf/UxfFormulaParser/parser.ts +0 -64
- package/src/uxf/UxfFormulaParser/utils/getErrorMsg.ts +0 -13
- package/src/uxf/constants.ts +0 -4
- package/src/uxf/index.ts +0 -2
- package/src/uxf/tectonicIdGenerator.ts +0 -78
|
@@ -0,0 +1,729 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrayShape,
|
|
3
|
+
BooleanShape,
|
|
4
|
+
NumberShape,
|
|
5
|
+
ObjectShape,
|
|
6
|
+
Plugin,
|
|
7
|
+
Shape,
|
|
8
|
+
UndefinedShape,
|
|
9
|
+
SourceFileShape,
|
|
10
|
+
IdentifierShape,
|
|
11
|
+
ts,
|
|
12
|
+
isUndefined,
|
|
13
|
+
getValueDeclaration,
|
|
14
|
+
VariableStatementShape,
|
|
15
|
+
ElementAccessExpressionShape,
|
|
16
|
+
TemplateExpressionShape,
|
|
17
|
+
TemplateSpanShape,
|
|
18
|
+
TaggedTemplateExpressionShape,
|
|
19
|
+
StringLiteralShape,
|
|
20
|
+
PropertyAccessShape,
|
|
21
|
+
NOW_FILE_EXTENSION,
|
|
22
|
+
DeletedShape,
|
|
23
|
+
removeReferences,
|
|
24
|
+
remove,
|
|
25
|
+
isFluentFile,
|
|
26
|
+
} from '@servicenow/sdk-build-core'
|
|
27
|
+
|
|
28
|
+
export const BasicSyntaxPlugin = Plugin.create({
|
|
29
|
+
name: 'BasicSyntaxPlugin',
|
|
30
|
+
files: [
|
|
31
|
+
{
|
|
32
|
+
entryPoint: true,
|
|
33
|
+
matcher: RegExp(`${NOW_FILE_EXTENSION}$`),
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
shapes: [
|
|
37
|
+
{
|
|
38
|
+
shape: DeletedShape,
|
|
39
|
+
commit(_, target) {
|
|
40
|
+
removeReferences(target)
|
|
41
|
+
remove(target)
|
|
42
|
+
return { success: true }
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
shape: UndefinedShape,
|
|
47
|
+
commit(_, target) {
|
|
48
|
+
if (!isUndefined(target)) {
|
|
49
|
+
target.replaceWithText('undefined')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { success: true }
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
shape: TemplateExpressionShape,
|
|
57
|
+
async commit(shape, target, { commit }) {
|
|
58
|
+
if (
|
|
59
|
+
!ts.Node.isTemplateExpression(target) &&
|
|
60
|
+
!ts.Node.isTaggedTemplateExpression(target) &&
|
|
61
|
+
!ts.Node.isNoSubstitutionTemplateLiteral(target)
|
|
62
|
+
) {
|
|
63
|
+
target.replaceWithText(shape.getCode())
|
|
64
|
+
return { success: true }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const template = ts.Node.isTaggedTemplateExpression(target) ? target.removeTag() : target
|
|
68
|
+
const targetSpans = ts.Node.isTemplateExpression(template) ? template.getTemplateSpans() : []
|
|
69
|
+
const shapeSpans = shape.getSpans()
|
|
70
|
+
|
|
71
|
+
if (shapeSpans.length !== targetSpans.length) {
|
|
72
|
+
template.replaceWithText(shape.getCode())
|
|
73
|
+
return { success: true }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (const [i, targetSpan] of targetSpans.entries()) {
|
|
77
|
+
const shapeSpan = shapeSpans[i]
|
|
78
|
+
if (!shapeSpan) {
|
|
79
|
+
throw new Error(`Expected shape to have a span at index ${i}`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await commit(shapeSpan, targetSpan)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { success: true }
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
shape: TemplateSpanShape,
|
|
90
|
+
async commit(shape, target, { commit }) {
|
|
91
|
+
if (!ts.Node.isTemplateSpan(target)) {
|
|
92
|
+
target.replaceWithText(shape.getCode())
|
|
93
|
+
return { success: true }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const literal = target.getLiteral()
|
|
97
|
+
if (shape.getLiteralText() !== literal.getLiteralText()) {
|
|
98
|
+
if (literal.isKind(ts.SyntaxKind.TemplateMiddle)) {
|
|
99
|
+
literal.replaceWithText(`}${shape.getLiteralText()}\${`)
|
|
100
|
+
} else if (literal.isKind(ts.SyntaxKind.TemplateTail)) {
|
|
101
|
+
literal.replaceWithText(`}${shape.getLiteralText()}\``)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
await commit(shape.getExpression(), target.getExpression())
|
|
106
|
+
return { success: true }
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
shape: StringLiteralShape,
|
|
111
|
+
async commit(shape, target, { commit }) {
|
|
112
|
+
const coerced = (() => {
|
|
113
|
+
try {
|
|
114
|
+
if (ts.Node.isTrueLiteral(target) || ts.Node.isFalseLiteral(target)) {
|
|
115
|
+
return shape.toBoolean()
|
|
116
|
+
} else if (ts.Node.isNumericLiteral(target)) {
|
|
117
|
+
const number = shape.toNumber()
|
|
118
|
+
|
|
119
|
+
// Turn the number back into a string and compare with the original string to avoid
|
|
120
|
+
// lossy conversions due to floating point precision or other factors
|
|
121
|
+
return number.getValue().toString() === shape.getValue() ? number : undefined
|
|
122
|
+
} else {
|
|
123
|
+
return undefined
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
return undefined
|
|
127
|
+
}
|
|
128
|
+
})()
|
|
129
|
+
|
|
130
|
+
if (coerced) {
|
|
131
|
+
await commit(coerced, target)
|
|
132
|
+
return { success: true }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (ts.Node.isTaggedTemplateExpression(target)) {
|
|
136
|
+
// Preserve tags when updating
|
|
137
|
+
target.getTemplate().replaceWithText(
|
|
138
|
+
new TemplateExpressionShape({
|
|
139
|
+
source: shape,
|
|
140
|
+
literalText: shape,
|
|
141
|
+
}).getCode()
|
|
142
|
+
)
|
|
143
|
+
} else {
|
|
144
|
+
target.replaceWithText(shape.getCode())
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { success: true }
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
shape: NumberShape,
|
|
152
|
+
commit(shape, target) {
|
|
153
|
+
if (ts.Node.isNumericLiteral(target) && target.getLiteralValue() === shape.getValue()) {
|
|
154
|
+
return { success: true }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
target.replaceWithText(shape.getValue().toString())
|
|
158
|
+
return { success: true }
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
shape: BooleanShape,
|
|
163
|
+
commit(shape, target) {
|
|
164
|
+
if (
|
|
165
|
+
(ts.Node.isTrueLiteral(target) || ts.Node.isFalseLiteral(target)) &&
|
|
166
|
+
target.getLiteralValue() === shape.getValue()
|
|
167
|
+
) {
|
|
168
|
+
return { success: true }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
target.replaceWithText(shape.getValue().toString())
|
|
172
|
+
return { success: true }
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
shape: ArrayShape,
|
|
177
|
+
async commit(shape, target, { commit }) {
|
|
178
|
+
if (!ts.Node.isArrayLiteralExpression(target)) {
|
|
179
|
+
target.replaceWithText(shape.getCode())
|
|
180
|
+
return { success: true }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Trim any excess elements
|
|
184
|
+
const targetElements = target.getElements()
|
|
185
|
+
const shapeElements = shape.getElements(false)
|
|
186
|
+
const excess = targetElements.length - shapeElements.length
|
|
187
|
+
for (let i = 1; i <= excess; i++) {
|
|
188
|
+
target.removeElement(targetElements.length - i)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Commit existing elements in the trimmed array
|
|
192
|
+
for (const [i, targetElement] of target.getElements().entries()) {
|
|
193
|
+
await commit(shape.getElement(i, false), targetElement)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Add new elements all at once, and we're done
|
|
197
|
+
const elementsToAdd = shapeElements.slice(target.getElements().length).map((e) => e.getCode())
|
|
198
|
+
if (elementsToAdd.length > 0) {
|
|
199
|
+
target.addElements(elementsToAdd)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return { success: true }
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
shape: ObjectShape,
|
|
207
|
+
async commit(shape, target, { commit }) {
|
|
208
|
+
if (!ts.Node.isObjectLiteralExpression(target)) {
|
|
209
|
+
target.replaceWithText(shape.getCode())
|
|
210
|
+
return { success: true }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const existingNames: Map<string, ts.Expression> = target
|
|
214
|
+
.getProperties()
|
|
215
|
+
.filter((p) => p.isKind(ts.SyntaxKind.PropertyAssignment))
|
|
216
|
+
.reduce(
|
|
217
|
+
(map, p) => map.set(getName(p), p.getInitializerOrThrow()),
|
|
218
|
+
new Map<string, ts.Expression>()
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
const propsToRetain = new Set<string>(['$meta'])
|
|
222
|
+
const propsToAdd: ts.PropertyAssignmentStructure[] = []
|
|
223
|
+
for (const [name, value] of shape.entries({ resolve: false })) {
|
|
224
|
+
const existingPropKey = [...shape.getAliases(name), name].find((aliasedKey) =>
|
|
225
|
+
existingNames.has(aliasedKey)
|
|
226
|
+
)
|
|
227
|
+
if (existingPropKey) {
|
|
228
|
+
if (existingPropKey !== name) {
|
|
229
|
+
target
|
|
230
|
+
.getPropertyOrThrow(existingPropKey)
|
|
231
|
+
.asKindOrThrow(ts.SyntaxKind.PropertyAssignment)
|
|
232
|
+
.getNameNode()
|
|
233
|
+
.replaceWithText(name)
|
|
234
|
+
}
|
|
235
|
+
await commit(value, existingNames.get(existingPropKey) as ts.Expression)
|
|
236
|
+
} else if (!value.equals(shape.getDefault(name))) {
|
|
237
|
+
propsToAdd.push({
|
|
238
|
+
name: ObjectShape.quotePropertyNameIfNeeded(name),
|
|
239
|
+
initializer: value.getCode(),
|
|
240
|
+
kind: ts.StructureKind.PropertyAssignment,
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
propsToRetain.add(name)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Add all missing props at once to improve performance
|
|
247
|
+
if (propsToAdd.length > 0) {
|
|
248
|
+
target.addPropertyAssignments(propsToAdd)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const propsToRemove = [...existingNames.keys()].filter((key) => !propsToRetain.has(key))
|
|
252
|
+
propsToRemove.forEach((prop) => {
|
|
253
|
+
target.getProperty(prop)?.asKindOrThrow(ts.SyntaxKind.PropertyAssignment).remove()
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
return { success: true }
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
shape: IdentifierShape,
|
|
261
|
+
commit(shape, target) {
|
|
262
|
+
if (ts.Node.isIdentifier(target) && target.getText() === shape.getName()) {
|
|
263
|
+
return { success: true }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
target.replaceWithText(shape.getName())
|
|
267
|
+
return { success: true }
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
shape: VariableStatementShape,
|
|
272
|
+
async commit(shape, target, { commit }) {
|
|
273
|
+
if (!ts.Node.isVariableStatement(target)) {
|
|
274
|
+
target.replaceWithText(shape.getCode())
|
|
275
|
+
return { success: true }
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (target.isExported() !== shape.isExported()) {
|
|
279
|
+
target.setIsExported(shape.isExported())
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const [declaration, otherDeclaration] = target.getDeclarations()
|
|
283
|
+
if (!declaration) {
|
|
284
|
+
throw new Error(`Variable statement is missing a declaration: ${target.getFullText()}`)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (otherDeclaration) {
|
|
288
|
+
removeReferences(otherDeclaration)
|
|
289
|
+
remove(otherDeclaration)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const variableName = shape.getVariableName()
|
|
293
|
+
if (declaration.getName() !== variableName.getName()) {
|
|
294
|
+
await commit(variableName, declaration.getNameNode())
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
await commit(shape.getInitializer(), declaration.getInitializerOrThrow())
|
|
298
|
+
return { success: true }
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
nodes: [
|
|
303
|
+
{
|
|
304
|
+
node: 'SourceFile',
|
|
305
|
+
async toShape(file, { diagnostics, transform }) {
|
|
306
|
+
if (isFluentFile(file)) {
|
|
307
|
+
const syntaxList = file.getChildSyntaxList()
|
|
308
|
+
if (!syntaxList) {
|
|
309
|
+
diagnostics.error(file, 'Fluent source file contains no meaningful content.')
|
|
310
|
+
return { success: false }
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
for (const child of syntaxList.getChildren()) {
|
|
314
|
+
if (ts.Node.isCommentNode(child)) {
|
|
315
|
+
continue
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const result = await transform.toShape(child)
|
|
319
|
+
if (!result.success) {
|
|
320
|
+
diagnostics.error(child, 'Unsupported statement in Fluent source file.')
|
|
321
|
+
return { success: false }
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
success: true,
|
|
328
|
+
value: new SourceFileShape({ file }),
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
node: 'StringLiteral',
|
|
334
|
+
toShape(node) {
|
|
335
|
+
return {
|
|
336
|
+
success: true,
|
|
337
|
+
value: new StringLiteralShape({ source: node, literalText: node.getLiteralValue() }),
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
node: 'NoSubstitutionTemplateLiteral',
|
|
343
|
+
toShape(node) {
|
|
344
|
+
return {
|
|
345
|
+
success: true,
|
|
346
|
+
value: new TemplateExpressionShape({ source: node, literalText: node.getLiteralValue() }),
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
node: 'NumericLiteral',
|
|
352
|
+
toShape(node) {
|
|
353
|
+
return {
|
|
354
|
+
success: true,
|
|
355
|
+
value: new NumberShape({ source: node, value: node.getLiteralValue() }),
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
node: 'NullKeyword',
|
|
361
|
+
toShape(node) {
|
|
362
|
+
return {
|
|
363
|
+
success: true,
|
|
364
|
+
value: new UndefinedShape({ source: node }),
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
node: 'TrueKeyword',
|
|
370
|
+
toShape(node) {
|
|
371
|
+
return {
|
|
372
|
+
success: true,
|
|
373
|
+
value: new BooleanShape({ source: node, value: true }),
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
node: 'FalseKeyword',
|
|
379
|
+
toShape(node) {
|
|
380
|
+
return {
|
|
381
|
+
success: true,
|
|
382
|
+
value: new BooleanShape({ source: node, value: false }),
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
node: 'AsExpression',
|
|
388
|
+
toShape(node, { transform }) {
|
|
389
|
+
return transform.toShape(node.getExpression())
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
node: 'ExportAssignment',
|
|
394
|
+
toShape(node, { transform }) {
|
|
395
|
+
return transform.toShape(node.getExpression())
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
node: 'ComputedPropertyName',
|
|
400
|
+
toShape(node, { transform }) {
|
|
401
|
+
return transform.toShape(node.getExpression())
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
node: 'PropertyAccessExpression',
|
|
406
|
+
async toShape(node, { transform, diagnostics }) {
|
|
407
|
+
const lastElementNode = node.getNameNode()
|
|
408
|
+
const lastElement = await transform.toShape(lastElementNode)
|
|
409
|
+
if (!lastElement.success || !lastElement.value.isIdentifier()) {
|
|
410
|
+
diagnostics.error(lastElementNode, 'Last element of property access expression is unsupported')
|
|
411
|
+
return { success: false }
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const expressionNode = node.getExpression()
|
|
415
|
+
const expression = await transform.toShape(expressionNode)
|
|
416
|
+
if (!expression.success || !expression.value.is([IdentifierShape, PropertyAccessShape])) {
|
|
417
|
+
diagnostics.error(expressionNode, 'Left side of property access expression is unsupported')
|
|
418
|
+
return { success: false }
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const elements = expression.value.isIdentifier()
|
|
422
|
+
? ([expression.value, lastElement.value] as const)
|
|
423
|
+
: ([...expression.value.getElements(), lastElement.value] as const)
|
|
424
|
+
|
|
425
|
+
return {
|
|
426
|
+
success: true,
|
|
427
|
+
value: new PropertyAccessShape({ source: node, elements }),
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
node: 'ExpressionStatement',
|
|
433
|
+
toShape(node, { transform }) {
|
|
434
|
+
return transform.toShape(node.getExpression())
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
node: 'Identifier',
|
|
439
|
+
async toShape(node, { transform }) {
|
|
440
|
+
if (isUndefined(node)) {
|
|
441
|
+
return {
|
|
442
|
+
success: true,
|
|
443
|
+
value: new UndefinedShape({ source: node }),
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const name = node.getSymbol()?.getName() ?? node.getText()
|
|
448
|
+
const valueDeclaration = getValueDeclaration(node)
|
|
449
|
+
const valueResult = valueDeclaration && (await transform.toShape(valueDeclaration))
|
|
450
|
+
|
|
451
|
+
return {
|
|
452
|
+
success: true,
|
|
453
|
+
value: valueResult?.success
|
|
454
|
+
? new IdentifierShape({ source: node, name, value: valueResult.value })
|
|
455
|
+
: new IdentifierShape({ source: node, name }),
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
node: 'Parameter',
|
|
461
|
+
toShape(node) {
|
|
462
|
+
return {
|
|
463
|
+
success: true,
|
|
464
|
+
value: new IdentifierShape({
|
|
465
|
+
source: node,
|
|
466
|
+
name: node.getName(),
|
|
467
|
+
}),
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
node: 'VariableStatement',
|
|
473
|
+
async toShape(node, { transform, diagnostics }) {
|
|
474
|
+
const kind = node.getDeclarationKind()
|
|
475
|
+
if (kind !== ts.VariableDeclarationKind.Const) {
|
|
476
|
+
diagnostics.error(
|
|
477
|
+
node.getDeclarationKindKeywords()[0] ?? node,
|
|
478
|
+
`Declaration kind "${kind}" is not supported. Only const variables are supported.`
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
return { success: false }
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const defaultKeyword = node.getDefaultKeyword()
|
|
485
|
+
if (defaultKeyword) {
|
|
486
|
+
diagnostics.error(defaultKeyword, 'Default exports are not supported')
|
|
487
|
+
return { success: false }
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const [declaration, otherDeclaration] = node.getDeclarations()
|
|
491
|
+
if (!declaration) {
|
|
492
|
+
diagnostics.error(node, 'Missing declaration in variable statement')
|
|
493
|
+
return { success: false }
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (otherDeclaration) {
|
|
497
|
+
diagnostics.error(
|
|
498
|
+
otherDeclaration,
|
|
499
|
+
'Additional declarations in variable statements are not supported'
|
|
500
|
+
)
|
|
501
|
+
return { success: false }
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const initializer = declaration.getInitializerOrThrow()
|
|
505
|
+
const initializerResult = await transform.toShape(initializer)
|
|
506
|
+
if (!initializerResult.success) {
|
|
507
|
+
diagnostics.error(initializer, 'Unsupported variable initializer')
|
|
508
|
+
return { success: false }
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return {
|
|
512
|
+
success: true,
|
|
513
|
+
value: new VariableStatementShape({
|
|
514
|
+
source: node,
|
|
515
|
+
variableName: new IdentifierShape({ source: node, name: declaration.getName() }),
|
|
516
|
+
initializer: initializerResult.value,
|
|
517
|
+
isExported: node.isExported(),
|
|
518
|
+
}),
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
node: 'VariableDeclaration',
|
|
524
|
+
toShape(node, { transform }) {
|
|
525
|
+
const initializer = node.getInitializer()
|
|
526
|
+
return initializer
|
|
527
|
+
? transform.toShape(initializer)
|
|
528
|
+
: {
|
|
529
|
+
success: true,
|
|
530
|
+
value: new UndefinedShape({ source: node }),
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
node: 'ArrayLiteralExpression',
|
|
536
|
+
async toShape(node, { transform }) {
|
|
537
|
+
const elements: Shape[] = []
|
|
538
|
+
for (const element of node.getElements()) {
|
|
539
|
+
const result = await transform.toShape(element)
|
|
540
|
+
if (!result.success) {
|
|
541
|
+
return { success: false }
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
elements.push(result.value)
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return {
|
|
548
|
+
success: true,
|
|
549
|
+
value: new ArrayShape({ source: node, elements }),
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
node: 'PropertyAssignment',
|
|
555
|
+
toShape(node, { transform, diagnostics }) {
|
|
556
|
+
const initializer = node.getInitializer()
|
|
557
|
+
if (!initializer) {
|
|
558
|
+
diagnostics.error(node, 'Property must have an initializer')
|
|
559
|
+
return { success: false }
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
return transform.toShape(initializer)
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
node: 'ObjectLiteralExpression',
|
|
567
|
+
async toShape(node, { transform, diagnostics }) {
|
|
568
|
+
const properties: Record<string, Shape> = {}
|
|
569
|
+
for (const property of node.getProperties()) {
|
|
570
|
+
if (!ts.Node.isPropertyAssignment(property)) {
|
|
571
|
+
diagnostics.error(property, 'Only property assignments are allowed')
|
|
572
|
+
continue
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const result = await transform.toShape(property)
|
|
576
|
+
if (!result.success) {
|
|
577
|
+
diagnostics.error(property, 'Failed to parse property')
|
|
578
|
+
return { success: false }
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const nameNode = property.getNameNode()
|
|
582
|
+
const name = ts.Node.isStringLiteral(nameNode) ? nameNode.getLiteralValue() : property.getName()
|
|
583
|
+
|
|
584
|
+
properties[name] = result.value
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
return {
|
|
588
|
+
success: true,
|
|
589
|
+
value: new ObjectShape({ source: node, properties }),
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
node: 'TemplateSpan',
|
|
595
|
+
async toShape(span, { transform, diagnostics }) {
|
|
596
|
+
const expression = await transform.toShape(span.getExpression())
|
|
597
|
+
if (!expression.success) {
|
|
598
|
+
diagnostics.error(span, 'Unsupported expression in template')
|
|
599
|
+
return { success: false }
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
success: true,
|
|
604
|
+
value: new TemplateSpanShape({
|
|
605
|
+
source: span,
|
|
606
|
+
expression: expression.value,
|
|
607
|
+
literalText: span.getLiteral().getLiteralText(),
|
|
608
|
+
}),
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
node: 'TemplateExpression',
|
|
614
|
+
async toShape(node, { transform, diagnostics }) {
|
|
615
|
+
const spans: TemplateSpanShape[] = []
|
|
616
|
+
for (const span of node.getTemplateSpans()) {
|
|
617
|
+
const result = await transform.toShape(span)
|
|
618
|
+
if (!result.success || !result.value.is(TemplateSpanShape)) {
|
|
619
|
+
diagnostics.error(span, 'Unsupported span in template expression')
|
|
620
|
+
return { success: false }
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
spans.push(result.value)
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return {
|
|
627
|
+
success: true,
|
|
628
|
+
value: new TemplateExpressionShape({
|
|
629
|
+
source: node,
|
|
630
|
+
literalText: node.getHead().getLiteralText(),
|
|
631
|
+
spans,
|
|
632
|
+
}),
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
node: 'TaggedTemplateExpression',
|
|
638
|
+
async toShape(node, { transform, diagnostics }) {
|
|
639
|
+
const template = node.getTemplate()
|
|
640
|
+
const templateResult = await transform.toShape(template)
|
|
641
|
+
if (!templateResult.success || !templateResult.value.is(TemplateExpressionShape)) {
|
|
642
|
+
diagnostics.error(template, 'Unsupported template in tagged template expression')
|
|
643
|
+
return { success: false }
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
return {
|
|
647
|
+
success: true,
|
|
648
|
+
value: new TaggedTemplateExpressionShape({
|
|
649
|
+
source: node,
|
|
650
|
+
tag: node.getTag().getText(),
|
|
651
|
+
template: templateResult.value,
|
|
652
|
+
}),
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
node: 'PrefixUnaryExpression',
|
|
658
|
+
toShape(node, { diagnostics }) {
|
|
659
|
+
if (
|
|
660
|
+
!ts.Node.isNumericLiteral(node.getOperand()) ||
|
|
661
|
+
node.getOperatorToken() !== ts.SyntaxKind.MinusToken
|
|
662
|
+
) {
|
|
663
|
+
diagnostics.error(node, 'Unsupported prefix unary expression')
|
|
664
|
+
return { success: false }
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
return {
|
|
668
|
+
success: true,
|
|
669
|
+
value: new NumberShape({
|
|
670
|
+
source: node,
|
|
671
|
+
value: -node.getOperand().asKindOrThrow(ts.SyntaxKind.NumericLiteral).getLiteralValue(),
|
|
672
|
+
}),
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
node: 'ElementAccessExpression',
|
|
678
|
+
async toShape(node, { transform, diagnostics }) {
|
|
679
|
+
const argumentExpression = node.getArgumentExpression()
|
|
680
|
+
if (!argumentExpression) {
|
|
681
|
+
diagnostics.error(node, 'Element access expression must have an argument')
|
|
682
|
+
return { success: false }
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const argumentShape = await transform.toShape(argumentExpression)
|
|
686
|
+
if (!argumentShape.success) {
|
|
687
|
+
diagnostics.error(node, 'Unsupported element access expression argument')
|
|
688
|
+
return { success: false }
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return {
|
|
692
|
+
success: true,
|
|
693
|
+
value: new ElementAccessExpressionShape({
|
|
694
|
+
source: node,
|
|
695
|
+
callee: node.getExpression().getText(),
|
|
696
|
+
arg: argumentShape.value,
|
|
697
|
+
}),
|
|
698
|
+
}
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
node: 'ImportDeclaration',
|
|
703
|
+
toShape(node) {
|
|
704
|
+
// TODO: This is just to prevent diagnostic errors. We should return a meaningful shape here.
|
|
705
|
+
return {
|
|
706
|
+
success: true,
|
|
707
|
+
value: Shape.noOp(node),
|
|
708
|
+
}
|
|
709
|
+
},
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
node: 'ExportDeclaration',
|
|
713
|
+
toShape(node) {
|
|
714
|
+
// TODO: This is just to prevent diagnostic errors. We should return a meaningful shape here.
|
|
715
|
+
return {
|
|
716
|
+
success: true,
|
|
717
|
+
value: Shape.noOp(node),
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
],
|
|
722
|
+
})
|
|
723
|
+
|
|
724
|
+
function getName(node: ts.PropertyAssignment): string {
|
|
725
|
+
const nameNode = node.getNameNode()
|
|
726
|
+
return ts.Node.isStringLiteral(nameNode) || ts.Node.isNoSubstitutionTemplateLiteral(nameNode)
|
|
727
|
+
? nameNode.getLiteralValue()
|
|
728
|
+
: nameNode.getText()
|
|
729
|
+
}
|