@marko/language-tools 1.0.0 → 1.0.1

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/index.js CHANGED
@@ -1808,24 +1808,26 @@ var ScriptExtractor = class {
1808
1808
  this.#extractor.write("(");
1809
1809
  }
1810
1810
  if (this.#scriptLang === "ts" /* ts */) {
1811
- this.#extractor.write(`function ${templateName}${typeParamsStr}(this: void) {
1812
- const input = 1 as any as Input${typeArgsStr};
1813
- const component = 1 as any as Component${typeArgsStr};
1814
- `);
1811
+ this.#extractor.write(
1812
+ `function ${templateName}${typeParamsStr}(this: void) {
1813
+ `
1814
+ );
1815
1815
  } else {
1816
1816
  this.#extractor.write(`/**${jsDocTemplateTagsStr}
1817
1817
  * @this {void}
1818
1818
  */
1819
1819
  function ${templateName}() {
1820
- const input = /** @type {Input${typeArgsStr}} */(${varShared("any")});
1821
- const component = /** @type {Component${typeArgsStr}} */(${varShared(
1822
- "any"
1823
- )});
1824
1820
  `);
1825
1821
  }
1826
- this.#extractor.write(` const out = ${varShared("out")};
1822
+ this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};
1823
+ const component = ${this.#getCastedType(`Component${typeArgsStr}`)};
1827
1824
  const state = ${varShared("state")}(component);
1828
- ${varShared("noop")}({ input, out, component, state });
1825
+ const $global = ${varShared("getGlobal")}(
1826
+ // @ts-expect-error We expect the compiler to error because we are checking if the MarkoRun.Context is defined.
1827
+ (${varShared("error")}, ${this.#getCastedType("MarkoRun.Context")})
1828
+ );
1829
+ const out = ${varShared("out")};
1830
+ ${varShared("noop")}({ input, component, state, out, $global });
1829
1831
  `);
1830
1832
  const body = this.#processBody(program);
1831
1833
  if (body == null ? void 0 : body.renderBody) {
@@ -2523,6 +2525,9 @@ const attrTags = ${varShared(
2523
2525
  }
2524
2526
  this.#extractor.write("}");
2525
2527
  }
2528
+ #getCastedType(type) {
2529
+ return this.#scriptLang === "ts" /* ts */ ? `${varShared("any")} as ${type}` : `/** @type {${type}} */(${varShared("any")})`;
2530
+ }
2526
2531
  #copyWithMutationsReplaced(range) {
2527
2532
  const mutations = this.#mutationOffsets;
2528
2533
  if (!mutations)
package/dist/index.mjs CHANGED
@@ -1775,24 +1775,26 @@ var ScriptExtractor = class {
1775
1775
  this.#extractor.write("(");
1776
1776
  }
1777
1777
  if (this.#scriptLang === "ts" /* ts */) {
1778
- this.#extractor.write(`function ${templateName}${typeParamsStr}(this: void) {
1779
- const input = 1 as any as Input${typeArgsStr};
1780
- const component = 1 as any as Component${typeArgsStr};
1781
- `);
1778
+ this.#extractor.write(
1779
+ `function ${templateName}${typeParamsStr}(this: void) {
1780
+ `
1781
+ );
1782
1782
  } else {
1783
1783
  this.#extractor.write(`/**${jsDocTemplateTagsStr}
1784
1784
  * @this {void}
1785
1785
  */
1786
1786
  function ${templateName}() {
1787
- const input = /** @type {Input${typeArgsStr}} */(${varShared("any")});
1788
- const component = /** @type {Component${typeArgsStr}} */(${varShared(
1789
- "any"
1790
- )});
1791
1787
  `);
1792
1788
  }
1793
- this.#extractor.write(` const out = ${varShared("out")};
1789
+ this.#extractor.write(` const input = ${this.#getCastedType(`Input${typeArgsStr}`)};
1790
+ const component = ${this.#getCastedType(`Component${typeArgsStr}`)};
1794
1791
  const state = ${varShared("state")}(component);
1795
- ${varShared("noop")}({ input, out, component, state });
1792
+ const $global = ${varShared("getGlobal")}(
1793
+ // @ts-expect-error We expect the compiler to error because we are checking if the MarkoRun.Context is defined.
1794
+ (${varShared("error")}, ${this.#getCastedType("MarkoRun.Context")})
1795
+ );
1796
+ const out = ${varShared("out")};
1797
+ ${varShared("noop")}({ input, component, state, out, $global });
1796
1798
  `);
1797
1799
  const body = this.#processBody(program);
1798
1800
  if (body == null ? void 0 : body.renderBody) {
@@ -2490,6 +2492,9 @@ const attrTags = ${varShared(
2490
2492
  }
2491
2493
  this.#extractor.write("}");
2492
2494
  }
2495
+ #getCastedType(type) {
2496
+ return this.#scriptLang === "ts" /* ts */ ? `${varShared("any")} as ${type}` : `/** @type {${type}} */(${varShared("any")})`;
2497
+ }
2493
2498
  #copyWithMutationsReplaced(range) {
2494
2499
  const mutations = this.#mutationOffsets;
2495
2500
  if (!mutations)
@@ -11,17 +11,17 @@ export declare class Extractor {
11
11
  #private;
12
12
  constructor(parsed: Parsed);
13
13
  write(str: string): this;
14
- copy(range: Range | string | false | void | null): this;
14
+ copy(range: Range | string | false | void | undefined | null): this;
15
15
  end(): Extracted;
16
16
  }
17
17
  export declare class Extracted {
18
18
  #private;
19
19
  constructor(parsed: Parsed, generated: string, tokens: Token[]);
20
- sourceOffsetAt(generatedOffset: number): number | void;
21
- sourcePositionAt(generatedOffset: number): Position | void;
20
+ sourceOffsetAt(generatedOffset: number): number | undefined;
21
+ sourcePositionAt(generatedOffset: number): Position | undefined;
22
22
  sourceLocationAt(generatedStart: number, generatedEnd: number): Location | undefined;
23
- generatedOffsetAt(sourceOffset: number): number | void;
24
- generatedPositionAt(sourceOffset: number): Position | void;
23
+ generatedOffsetAt(sourceOffset: number): number | undefined;
24
+ generatedPositionAt(sourceOffset: number): Position | undefined;
25
25
  generatedLocationAt(sourceStart: number, sourceEnd: number): Location | undefined;
26
26
  toString(): string;
27
27
  }
@@ -19,6 +19,10 @@ declare global {
19
19
  export const never: never;
20
20
  export const any: any;
21
21
 
22
+ export function getGlobal<Override>(
23
+ override: Override
24
+ ): 1 extends Override & 0 ? Marko.Global : Override;
25
+
22
26
  export function attrTagNames<Input, Keys extends keyof Input>(
23
27
  input: Input
24
28
  ): Record<string, never> & {
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
3
  "description": "Marko Language Tools",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
6
6
  "dependencies": {
7
7
  "@babel/helper-validator-identifier": "^7.19.1",
8
8
  "@babel/parser": "^7.21.2",
9
- "htmljs-parser": "^5.2.4",
9
+ "htmljs-parser": "^5.4.0",
10
10
  "relative-import-path": "^1.0.0"
11
11
  },
12
12
  "devDependencies": {
13
13
  "@babel/code-frame": "^7.18.6",
14
- "@marko/compiler": "^5.23.6",
14
+ "@marko/compiler": "^5.26.0",
15
15
  "@types/babel__code-frame": "^7.0.3",
16
16
  "@types/babel__helper-validator-identifier": "^7.15.0",
17
17
  "@typescript/vfs": "^1.4.0",
18
- "marko": "^5.22.7",
18
+ "marko": "^5.24.0",
19
19
  "mitata": "^0.1.6",
20
20
  "tsx": "^3.12.3"
21
21
  },