Package not found. Please check the package name and try again.

@player-tools/json-language-service 0.8.1 → 0.8.2--canary.169.3835

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.
@@ -1,125 +0,0 @@
1
- import { addLast, omit, set } from "timm";
2
- import { DiagnosticSeverity } from "vscode-languageserver-types";
3
- import type { PlayerLanguageService, PlayerLanguageServicePlugin } from "..";
4
- import type { AssetASTNode, ObjectASTNode, ViewASTNode } from "../parser";
5
- import { getNodeValue } from "../parser";
6
- import type {
7
- ASTVisitor,
8
- DocumentContext,
9
- ValidationContext,
10
- Violation,
11
- } from "../types";
12
- import { formatLikeNode } from "../utils";
13
-
14
- /** Create a visitor for handling old template syntax */
15
- function createRuleVisitor(
16
- context: ValidationContext,
17
- docInfo: DocumentContext
18
- ): ASTVisitor {
19
- /** Check a node for any signs of a legacy-template */
20
- const checkForLegacyTemplate = (
21
- node: ObjectASTNode | AssetASTNode | ViewASTNode
22
- ) => {
23
- // check if it has any of the 3 props we care about
24
-
25
- const templateDataProp = node.properties.find(
26
- (p) => p.keyNode.value === "templateData"
27
- );
28
- const templateValueProp = node.properties.find(
29
- (p) => p.keyNode.value === "template"
30
- );
31
- const templateOutputProp = node.properties.find(
32
- (p) => p.keyNode.value === "templateOutput"
33
- );
34
-
35
- // If we don't have any of those props, or we just have the`template` prop and it points to an array, skip it all, we good.
36
- if (
37
- !templateDataProp &&
38
- !templateOutputProp &&
39
- (!templateValueProp || templateValueProp.valueNode?.type === "array")
40
- ) {
41
- return;
42
- }
43
-
44
- const templateViolation: Omit<Violation, "node"> = {
45
- severity: DiagnosticSeverity.Error,
46
- message: `Migrate to the template[] syntax.`,
47
- fix: () => {
48
- // Create the new template object;
49
- const path = [
50
- "template",
51
- templateValueProp?.valueNode?.type === "array"
52
- ? templateValueProp.valueNode.children.length
53
- : 0,
54
- ];
55
-
56
- const newTemplateObj = {
57
- value:
58
- templateValueProp?.valueNode?.type !== "array" &&
59
- templateValueProp?.valueNode
60
- ? getNodeValue(templateValueProp?.valueNode)
61
- : {},
62
- output: templateOutputProp?.valueNode?.jsonNode.value ?? "",
63
- data: templateDataProp?.valueNode?.jsonNode.value ?? "",
64
- };
65
-
66
- const oldValue = getNodeValue(node);
67
- let newValue = omit(oldValue, "templateData");
68
- newValue = omit(newValue, "templateOutput");
69
-
70
- if (templateValueProp?.valueNode?.type !== "array") {
71
- newValue = omit(newValue, "template");
72
- }
73
-
74
- newValue = set(
75
- newValue,
76
- "template",
77
- addLast(newValue.template ?? [], newTemplateObj)
78
- );
79
-
80
- return {
81
- edit: {
82
- type: "replace",
83
- path,
84
- node,
85
- value: formatLikeNode(docInfo.document, node, newValue),
86
- },
87
- name: "Convert to template[]",
88
- };
89
- },
90
- };
91
-
92
- if (templateDataProp) {
93
- context.addViolation({
94
- ...templateViolation,
95
- node: templateDataProp,
96
- });
97
- }
98
-
99
- if (templateOutputProp) {
100
- context.addViolation({
101
- ...templateViolation,
102
- node: templateOutputProp,
103
- });
104
- }
105
- };
106
-
107
- return {
108
- ViewNode: checkForLegacyTemplate,
109
- AssetNode: checkForLegacyTemplate,
110
- ObjectNode: checkForLegacyTemplate,
111
- };
112
- }
113
-
114
- /** A plugin that handles the old legacy template syntax */
115
- export class LegacyTemplatePlugin implements PlayerLanguageServicePlugin {
116
- name = "legacy-template";
117
-
118
- apply(service: PlayerLanguageService) {
119
- service.hooks.validate.tap(this.name, async (ctx, validationContext) => {
120
- validationContext.useASTVisitor(
121
- createRuleVisitor(validationContext, ctx)
122
- );
123
- });
124
- }
125
- }
@@ -1,7 +0,0 @@
1
- import type { PlayerLanguageService, PlayerLanguageServicePlugin } from "..";
2
- /** A plugin that validates and corrects the usage of non-asset actions in a view */
3
- export declare class LegacyActionPlugin implements PlayerLanguageServicePlugin {
4
- name: string;
5
- apply(service: PlayerLanguageService): void;
6
- }
7
- //# sourceMappingURL=legacy-action-plugin.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { PlayerLanguageService, PlayerLanguageServicePlugin } from "..";
2
- /** A plugin that handles the old legacy template syntax */
3
- export declare class LegacyTemplatePlugin implements PlayerLanguageServicePlugin {
4
- name: string;
5
- apply(service: PlayerLanguageService): void;
6
- }
7
- //# sourceMappingURL=legacy-template-plugin.d.ts.map