ripple 0.3.13 → 0.3.14

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/package.json +5 -30
  3. package/src/runtime/array.js +38 -38
  4. package/src/runtime/create-subscriber.js +2 -2
  5. package/src/runtime/internal/client/bindings.js +4 -6
  6. package/src/runtime/internal/client/events.js +8 -3
  7. package/src/runtime/internal/client/hmr.js +5 -17
  8. package/src/runtime/internal/client/runtime.js +1 -0
  9. package/src/runtime/internal/server/blocks.js +7 -9
  10. package/src/runtime/internal/server/index.js +14 -22
  11. package/src/runtime/media-query.js +34 -33
  12. package/src/runtime/object.js +7 -10
  13. package/src/runtime/proxy.js +2 -3
  14. package/src/runtime/reactive-value.js +23 -21
  15. package/src/utils/ast.js +1 -1
  16. package/src/utils/attributes.js +43 -0
  17. package/src/utils/builders.js +2 -2
  18. package/tests/client/basic/basic.errors.test.rsrx +1 -1
  19. package/tests/client/basic/basic.styling.test.rsrx +1 -1
  20. package/tests/client/compiler/compiler.assignments.test.rsrx +1 -1
  21. package/tests/client/compiler/compiler.attributes.test.rsrx +1 -1
  22. package/tests/client/compiler/compiler.basic.test.rsrx +13 -13
  23. package/tests/client/compiler/compiler.tracked-access.test.rsrx +1 -1
  24. package/tests/client/compiler/compiler.try-in-function.test.rsrx +1 -1
  25. package/tests/client/compiler/compiler.typescript.test.rsrx +1 -1
  26. package/tests/client/css/global-additional-cases.test.rsrx +1 -1
  27. package/tests/client/css/global-advanced-selectors.test.rsrx +1 -1
  28. package/tests/client/css/global-at-rules.test.rsrx +1 -1
  29. package/tests/client/css/global-basic.test.rsrx +1 -1
  30. package/tests/client/css/global-classes-ids.test.rsrx +1 -1
  31. package/tests/client/css/global-combinators.test.rsrx +1 -1
  32. package/tests/client/css/global-complex-nesting.test.rsrx +1 -1
  33. package/tests/client/css/global-edge-cases.test.rsrx +1 -1
  34. package/tests/client/css/global-keyframes.test.rsrx +1 -1
  35. package/tests/client/css/global-nested.test.rsrx +1 -1
  36. package/tests/client/css/global-pseudo.test.rsrx +1 -1
  37. package/tests/client/css/global-scoping.test.rsrx +1 -1
  38. package/tests/client/css/style-identifier.test.rsrx +1 -1
  39. package/tests/client/return.test.rsrx +1 -1
  40. package/tests/hydration/build-components.js +1 -1
  41. package/tests/server/style-identifier.test.rsrx +1 -1
  42. package/tests/setup-server.js +1 -1
  43. package/tests/utils/compiler-compat-config.test.js +1 -1
  44. package/src/compiler/comment-utils.js +0 -91
  45. package/src/compiler/errors.js +0 -77
  46. package/src/compiler/identifier-utils.js +0 -80
  47. package/src/compiler/index.d.ts +0 -127
  48. package/src/compiler/index.js +0 -89
  49. package/src/compiler/phases/1-parse/index.js +0 -3007
  50. package/src/compiler/phases/1-parse/style.js +0 -704
  51. package/src/compiler/phases/2-analyze/css-analyze.js +0 -160
  52. package/src/compiler/phases/2-analyze/index.js +0 -2208
  53. package/src/compiler/phases/2-analyze/prune.js +0 -1131
  54. package/src/compiler/phases/2-analyze/validation.js +0 -168
  55. package/src/compiler/phases/3-transform/client/index.js +0 -5264
  56. package/src/compiler/phases/3-transform/segments.js +0 -2125
  57. package/src/compiler/phases/3-transform/server/index.js +0 -1749
  58. package/src/compiler/phases/3-transform/stylesheet.js +0 -545
  59. package/src/compiler/scope.js +0 -476
  60. package/src/compiler/source-map-utils.js +0 -358
  61. package/src/compiler/types/acorn.d.ts +0 -11
  62. package/src/compiler/types/estree-jsx.d.ts +0 -11
  63. package/src/compiler/types/estree.d.ts +0 -11
  64. package/src/compiler/types/index.d.ts +0 -1411
  65. package/src/compiler/types/parse.d.ts +0 -1723
  66. package/src/compiler/utils.js +0 -1258
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('basic client > styling', () => {
4
4
  it('renders with styling scoped to component', () => {
@@ -1,5 +1,5 @@
1
1
  import { RippleArray, effect, track, untrack } from 'ripple';
2
- import { compile } from 'ripple/compiler';
2
+ import { compile } from '@tsrx/ripple';
3
3
 
4
4
  const EFFECT_BODY_REGEX = /_\$\_\.effect\(\(\) => \{([\s\S]*?)\n\t\}\);/;
5
5
 
@@ -1,4 +1,4 @@
1
- import { parse, compile } from 'ripple/compiler';
1
+ import { parse, compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('compiler > attributes', () => {
4
4
  it('generates valid JavaScript for component props with hyphenated attributes', () => {
@@ -1,5 +1,5 @@
1
- import { parse, compile, compile_to_volar_mappings } from 'ripple/compiler';
2
- import { obfuscate_identifier } from 'ripple/compiler/internal/identifier/utils';
1
+ import { parse, compile, compile_to_volar_mappings } from '@tsrx/ripple';
2
+ import { obfuscateIdentifier } from '@tsrx/core';
3
3
  import type * as AST from 'estree';
4
4
 
5
5
  function count_occurrences(string: string, subString: string): number {
@@ -59,7 +59,7 @@ describe('compiler > basics', () => {
59
59
  const explicit_text = elements[1].children[0] as AST.TextNode;
60
60
 
61
61
  expect(elements).toHaveLength(2);
62
- expect(expression.type).toBe('RippleExpression');
62
+ expect(expression.type).toBe('TSRXExpression');
63
63
  expect((expression.expression as AST.Identifier).name).toBe('markup');
64
64
  expect(explicit_text.type).toBe('Text');
65
65
  expect((explicit_text.expression as AST.Identifier).name).toBe('markup');
@@ -321,15 +321,15 @@ describe('compiler > basics', () => {
321
321
  // `;
322
322
  // const result = compile_to_volar_mappings(source, 'test.ripple').code;
323
323
 
324
- // expect(count_occurrences(result, obfuscate_identifier('RippleArray'))).toBe(2);
324
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleArray'))).toBe(2);
325
325
  // expect(count_occurrences(result, 'TA')).toBe(1);
326
- // expect(count_occurrences(result, obfuscate_identifier('RippleObject'))).toBe(2);
326
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleObject'))).toBe(2);
327
327
  // expect(count_occurrences(result, 'TO')).toBe(1);
328
- // expect(count_occurrences(result, obfuscate_identifier('RippleSet'))).toBe(2);
328
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleSet'))).toBe(2);
329
329
  // expect(count_occurrences(result, 'TS')).toBe(1);
330
- // expect(count_occurrences(result, obfuscate_identifier('RippleMap'))).toBe(2);
330
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleMap'))).toBe(2);
331
331
  // expect(count_occurrences(result, 'TM')).toBe(1);
332
- // expect(count_occurrences(result, obfuscate_identifier('createRefKey'))).toBe(2);
332
+ // expect(count_occurrences(result, obfuscateIdentifier('createRefKey'))).toBe(2);
333
333
  // expect(count_occurrences(result, 'crk')).toBe(1);
334
334
  // },
335
335
  // );
@@ -347,11 +347,11 @@ describe('compiler > basics', () => {
347
347
  // `;
348
348
  // const result = compile_to_volar_mappings(source, 'test.ripple').code;
349
349
 
350
- // expect(count_occurrences(result, obfuscate_identifier('RippleArray'))).toBe(2);
351
- // expect(count_occurrences(result, obfuscate_identifier('RippleObject'))).toBe(2);
352
- // expect(count_occurrences(result, obfuscate_identifier('RippleSet'))).toBe(2);
353
- // expect(count_occurrences(result, obfuscate_identifier('RippleMap'))).toBe(2);
354
- // expect(count_occurrences(result, obfuscate_identifier('createRefKey'))).toBe(2);
350
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleArray'))).toBe(2);
351
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleObject'))).toBe(2);
352
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleSet'))).toBe(2);
353
+ // expect(count_occurrences(result, obfuscateIdentifier('RippleMap'))).toBe(2);
354
+ // expect(count_occurrences(result, obfuscateIdentifier('createRefKey'))).toBe(2);
355
355
  // });
356
356
 
357
357
  it('prints longhand tracked property values in to_ts output while preserving [\'#v\']', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('Compiler: Tracked Object Direct Access Checks', () => {
4
4
  it('should error on direct access to __v of a tracked object', () => {
@@ -1,4 +1,4 @@
1
- import { compile_to_volar_mappings } from 'ripple/compiler';
1
+ import { compile_to_volar_mappings } from '@tsrx/ripple';
2
2
 
3
3
  function count_occurrences(string: string, sub_string: string): number {
4
4
  let count = 0;
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('compiler > typescript', () => {
4
4
  it('compiles TSInstantiationExpression', () => {
@@ -1,5 +1,5 @@
1
1
  import { track } from 'ripple';
2
- import { compile } from 'ripple/compiler';
2
+ import { compile } from '@tsrx/ripple';
3
3
 
4
4
  describe('CSS :global additional use cases', () => {
5
5
  it('handles :global as modifier with dot notation', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global with advanced selectors', () => {
4
4
  it('handles :global with ::slotted()', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global with @media and @supports', () => {
4
4
  it('handles :global inside @media queries', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global basic tests', () => {
4
4
  it('applies global selector to all elements', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global with classes and IDs', () => {
4
4
  it('handles :global with single class', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global with combinators', () => {
4
4
  it('handles :global with child combinator', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global with complex nesting', () => {
4
4
  it('handles :global block with nested selectors', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global edge cases', () => {
4
4
  it('handles multiple :global selectors in one rule', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global with keyframes', () => {
4
4
  it('handles -global- prefix for keyframes', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global nested blocks', () => {
4
4
  it('handles nested global blocks', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global with pseudo-classes', () => {
4
4
  it('handles :global with :has()', () => {
@@ -1,4 +1,4 @@
1
- import { compile } from 'ripple/compiler';
1
+ import { compile } from '@tsrx/ripple';
2
2
 
3
3
  describe('CSS :global scoping verification', () => {
4
4
  it('verifies scoped styles are isolated', () => {
@@ -1,5 +1,5 @@
1
1
  import { track } from 'ripple';
2
- import { compile } from 'ripple/compiler';
2
+ import { compile } from '@tsrx/ripple';
3
3
 
4
4
  describe('#style identifier', () => {
5
5
  describe('basic usage with components', () => {
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { flushSync, track } from 'ripple';
3
- import { compile } from 'ripple/compiler';
3
+ import { compile } from '@tsrx/ripple';
4
4
 
5
5
  describe('returns in prohibited scopes', () => {
6
6
  it('throws error when return is used in module scope', () => {
@@ -4,7 +4,7 @@
4
4
  * Or used as vitest globalSetup
5
5
  */
6
6
 
7
- import { compile } from 'ripple/compiler';
7
+ import { compile } from '@tsrx/ripple';
8
8
  import { readFileSync, writeFileSync, mkdirSync, readdirSync } from 'fs';
9
9
  import { join, basename } from 'path';
10
10
  import { fileURLToPath } from 'url';
@@ -1,5 +1,5 @@
1
1
  import { track } from 'ripple';
2
- import { compile } from 'ripple/compiler';
2
+ import { compile } from '@tsrx/ripple';
3
3
 
4
4
  describe('#style identifier (server)', () => {
5
5
  describe('basic usage with components', () => {
@@ -1,6 +1,6 @@
1
1
  import { expect } from 'vitest';
2
2
  import { render } from 'ripple/server';
3
- import { compile } from 'ripple/compiler';
3
+ import { compile } from '@tsrx/ripple';
4
4
  import { parseHTML } from 'linkedom';
5
5
 
6
6
  globalThis.render = render;
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { compile } from 'ripple/compiler';
2
+ import { compile } from '@tsrx/ripple';
3
3
 
4
4
  const source = `
5
5
  component App() {
@@ -1,91 +0,0 @@
1
- /**
2
- * @import * as AST from 'estree'
3
- */
4
-
5
- /**
6
- * Check if a comment is a TypeScript pragma (line comment)
7
- * @param {AST.CommentWithLocation} comment
8
- * @returns {boolean}
9
- */
10
- export function is_ts_pragma(comment) {
11
- if (comment.type !== 'Line') return false;
12
-
13
- const pragmas = ['@ts-ignore', '@ts-expect-error', '@ts-nocheck', '@ts-check'];
14
- return pragmas.some((pragma) => comment.value.trimStart().startsWith(pragma));
15
- }
16
-
17
- /**
18
- * Check if a comment is a triple-slash directive
19
- * /// <reference path="..." />
20
- * @param {AST.CommentWithLocation} comment
21
- * @returns {boolean}
22
- */
23
- export function is_triple_slash_directive(comment) {
24
- if (comment.type !== 'Line') return false;
25
-
26
- // Triple slash directives start with / after the // is stripped
27
- // So the value should start with / followed by <reference, <amd-module, or <amd-dependency
28
- const value = comment.value.trim();
29
- return /^\/\s*<(reference|amd-module|amd-dependency)/.test(value);
30
- }
31
-
32
- /**
33
- * Check if a comment is a JSDoc comment with TypeScript annotations
34
- * Examples: block comments containing `@type`, `@typedef`, `@param`, `@returns`, etc.
35
- * @param {AST.CommentWithLocation} comment
36
- * @returns {boolean}
37
- */
38
- export function is_jsdoc_ts_annotation(comment) {
39
- if (comment.type !== 'Block') return false;
40
-
41
- // JSDoc comments start with /** which means the value starts with * after /* is stripped
42
- if (!comment.value.startsWith('*')) return false;
43
-
44
- // Check if it contains TypeScript-relevant tags
45
- const tsAnnotations = [
46
- '@type',
47
- '@typedef',
48
- '@param',
49
- '@returns',
50
- '@template',
51
- '@extends',
52
- '@implements',
53
- '@satisfies',
54
- '@overload',
55
- '@import',
56
- ];
57
-
58
- return tsAnnotations.some((annotation) => comment.value.includes(annotation));
59
- }
60
-
61
- /**
62
- * Check if a comment should be preserved in to_ts mode
63
- * @param {AST.CommentWithLocation} comment
64
- * @returns {boolean}
65
- */
66
- export function should_preserve_comment(comment) {
67
- return (
68
- is_ts_pragma(comment) || is_triple_slash_directive(comment) || is_jsdoc_ts_annotation(comment)
69
- );
70
- }
71
-
72
- /**
73
- * Format a comment for output
74
- * @param {AST.CommentWithLocation} comment
75
- * @returns {string}
76
- */
77
- export function format_comment(comment) {
78
- if (comment.type === 'Line') {
79
- // Check if it's a triple-slash directive (value starts with /)
80
- if (comment.value.trimStart().startsWith('/')) {
81
- return `/// ${comment.value.trimStart().slice(1)}`;
82
- }
83
- return `// ${comment.value.trim()}`;
84
- } else {
85
- // Block comment - check if it's a JSDoc (value starts with *)
86
- if (comment.value.startsWith('*')) {
87
- return `/** ${comment.value.trim().slice(1)} */`;
88
- }
89
- return `/* ${comment.value.trim()} */`;
90
- }
91
- }
@@ -1,77 +0,0 @@
1
- /**
2
- @import * as AST from 'estree';
3
- @import { RippleCompileError } from 'ripple/compiler';
4
- */
5
-
6
- /**
7
- *
8
- * @param {string} message
9
- * @param {string | null} filename
10
- * @param {AST.Node | AST.NodeWithLocation} node
11
- * @param {RippleCompileError[]} [errors]
12
- * @param {AST.CommentWithLocation[]} [comments]
13
- * @returns {void}
14
- */
15
- export function error(message, filename, node, errors, comments) {
16
- if (errors && comments && is_ripple_error_suppressed(node, comments)) {
17
- return;
18
- }
19
-
20
- const error = /** @type {RippleCompileError} */ (new Error(message));
21
-
22
- // same as the acorn compiler error
23
- error.pos = node.start ?? undefined;
24
- error.raisedAt = node.end ?? undefined;
25
-
26
- // custom properties
27
- error.fileName = filename;
28
- error.end = node.end ?? undefined;
29
- error.loc = !node.loc
30
- ? undefined
31
- : {
32
- start: {
33
- line: node.loc.start.line,
34
- column: node.loc.start.column,
35
- },
36
- end: {
37
- line: node.loc.end.line,
38
- column: node.loc.end.column,
39
- },
40
- };
41
-
42
- if (errors) {
43
- error.type = 'usage';
44
- errors.push(error);
45
- return;
46
- }
47
-
48
- error.type = 'fatal';
49
- throw error;
50
- }
51
-
52
- /**
53
- * @param {AST.CommentWithLocation} comment
54
- * @return {boolean}
55
- */
56
- function is_ripple_error_suppress_comment(comment) {
57
- const text = comment.value.trim();
58
- return text.startsWith('@ripple-ignore') || text.startsWith('@ripple-expect-error');
59
- }
60
-
61
- /**
62
- * @param {AST.Node | AST.NodeWithLocation} node
63
- * @param {AST.CommentWithLocation[]} comments
64
- */
65
- function is_ripple_error_suppressed(node, comments) {
66
- if (node.loc) {
67
- const node_start_line = node.loc.start.line;
68
- for (const comment of comments) {
69
- if (comment.type === 'Line' && comment.loc.start.line === node_start_line - 1) {
70
- if (is_ripple_error_suppress_comment(comment)) {
71
- return true;
72
- }
73
- }
74
- }
75
- }
76
- return false;
77
- }
@@ -1,80 +0,0 @@
1
- export const IDENTIFIER_OBFUSCATION_PREFIX = '_$_';
2
- export const STYLE_IDENTIFIER = IDENTIFIER_OBFUSCATION_PREFIX + encode_utf16_char('#') + 'style';
3
- export const SERVER_IDENTIFIER = IDENTIFIER_OBFUSCATION_PREFIX + encode_utf16_char('#') + 'server';
4
- export const CSS_HASH_IDENTIFIER = IDENTIFIER_OBFUSCATION_PREFIX + 'hash';
5
-
6
- const DECODE_UTF16_REGEX = /_u([0-9a-fA-F]{4})_/g;
7
-
8
- /**
9
- * @param {string} char
10
- * @returns {string}
11
- */
12
- function encode_utf16_char(char) {
13
- return `_u${('0000' + char.charCodeAt(0).toString(16)).slice(-4)}_`;
14
- }
15
-
16
- /**
17
- * Finds the next uppercase character or returns name.length
18
- * @param {string} name
19
- * @param {number} start
20
- * @returns {number}
21
- */
22
- function find_next_uppercase(name, start) {
23
- for (let i = start; i < name.length; i++) {
24
- if (name[i] === name[i].toUpperCase()) {
25
- return i;
26
- }
27
- }
28
- return name.length;
29
- }
30
-
31
- /**
32
- * @param {string} encoded
33
- * @returns {string}
34
- */
35
- function decode_utf16_string(encoded) {
36
- return encoded.replace(DECODE_UTF16_REGEX, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
37
- }
38
-
39
- /**
40
- * @param {string} name
41
- * @returns {string}
42
- */
43
- export function obfuscate_identifier(name) {
44
- const first_char = name[0];
45
- let start = 0;
46
- if (first_char === '@' || first_char === '#') {
47
- const encoded = encode_utf16_char(first_char);
48
- name = encoded + name.slice(1);
49
- start = encoded.length;
50
- } else if (first_char === first_char.toUpperCase()) {
51
- start = 1;
52
- }
53
- const index = find_next_uppercase(name, start);
54
-
55
- const first_part = name.slice(0, index);
56
- const second_part = name.slice(index);
57
-
58
- return (
59
- IDENTIFIER_OBFUSCATION_PREFIX +
60
- (second_part ? second_part + '__' + first_part : first_part + '__')
61
- );
62
- }
63
-
64
- /**
65
- * @param {string} name
66
- * @returns {boolean}
67
- */
68
- export function is_identifier_obfuscated(name) {
69
- return name.startsWith(IDENTIFIER_OBFUSCATION_PREFIX);
70
- }
71
-
72
- /**
73
- * @param {string} name
74
- * @returns {string}
75
- */
76
- export function deobfuscate_identifier(name) {
77
- name = name.replaceAll(IDENTIFIER_OBFUSCATION_PREFIX, '');
78
- const parts = name.split('__');
79
- return decode_utf16_string((parts[1] ? parts[1] : '') + parts[0]);
80
- }
@@ -1,127 +0,0 @@
1
- import type * as AST from 'estree';
2
- import type {
3
- CodeInformation as VolarCodeInformation,
4
- Mapping as VolarMapping,
5
- } from '@volar/language-core';
6
- import type { DocumentHighlightKind } from 'vscode-languageserver-types';
7
- import type { RawSourceMap } from 'source-map';
8
-
9
- // ============================================================================
10
- // Compiler API Exports
11
- // ============================================================================
12
- /**
13
- * Result of compilation operation
14
- */
15
- export interface CompileResult {
16
- /** The transformed AST */
17
- ast: AST.Program;
18
- /** The generated JavaScript code with source map */
19
- js: {
20
- code: string;
21
- map: RawSourceMap;
22
- };
23
- /** The generated CSS */
24
- css: string;
25
- }
26
-
27
- export interface DefinitionLocation {
28
- embeddedId: string; // e.g., 'style_0', 'style_1'
29
- start: number; // start offset
30
- end: number; // end offset
31
- }
32
-
33
- export interface PluginActionOverrides {
34
- /** Whether to enable word document highlighting for this mapping */
35
- wordHighlight?: {
36
- kind: DocumentHighlightKind;
37
- };
38
- /** TypeScript diagnostic codes to suppress for this mapping */
39
- suppressedDiagnostics?: number[];
40
- /** Custom hover documentation for this mapping, false to disable */
41
- hover?: string | false | ((content: string) => string);
42
- /** Custom definition info for this mapping, false to disable */
43
- definition?:
44
- | {
45
- description?: string; // just for reference
46
- // Generic location for embedded content (CSS, etc.)
47
- location?: DefinitionLocation;
48
- // Replace the type name in hover/definition with a different name
49
- // And provide the path to import the type definitions from
50
- // the `ripple` package directory, e.g. `types/index.d.ts`
51
- // Currently only supported by the definition plugin
52
- typeReplace?: {
53
- name: string;
54
- path: string;
55
- };
56
- }
57
- | false;
58
- }
59
-
60
- export interface CustomMappingData extends PluginActionOverrides {
61
- embeddedId?: string; // e.g. css regions: 'style_0', 'style_1', etc.
62
- content?: string; // (e.g., css code)
63
- }
64
-
65
- export interface MappingData extends VolarCodeInformation {
66
- customData: CustomMappingData;
67
- }
68
-
69
- export interface CodeMapping extends Omit<VolarMapping<MappingData>, 'generatedLengths'> {
70
- generatedLengths: number[];
71
- data: MappingData;
72
- }
73
-
74
- export interface VolarMappingsResult {
75
- code: string;
76
- mappings: CodeMapping[];
77
- cssMappings: CodeMapping[];
78
- errors: RippleCompileError[];
79
- }
80
-
81
- export interface RippleCompileError extends Error {
82
- pos: number | undefined;
83
- raisedAt: number | undefined;
84
- end: number | undefined;
85
- loc: AST.SourceLocation | undefined;
86
- fileName: string | null;
87
- type: 'fatal' | 'usage';
88
- }
89
-
90
- /**
91
- * Compilation options
92
- */
93
-
94
- interface SharedCompileOptions {
95
- minify_css?: boolean;
96
- dev?: boolean;
97
- }
98
- export interface CompileOptions extends SharedCompileOptions {
99
- mode?: 'client' | 'server';
100
- hmr?: boolean;
101
- compat_kinds?: string[];
102
- }
103
-
104
- export interface ParseOptions {
105
- loose?: boolean;
106
- errors?: RippleCompileError[];
107
- comments?: AST.CommentWithLocation[];
108
- }
109
-
110
- export interface AnalyzeOptions
111
- extends ParseOptions, Pick<CompileOptions, 'mode' | 'compat_kinds'> {
112
- errors?: RippleCompileError[];
113
- to_ts?: boolean;
114
- }
115
-
116
- export interface VolarCompileOptions
117
- extends Omit<ParseOptions, 'errors' | 'comments'>, SharedCompileOptions {}
118
-
119
- export function parse(source: string, options?: ParseOptions): AST.Program;
120
-
121
- export function compile(source: string, filename: string, options?: CompileOptions): CompileResult;
122
-
123
- export function compile_to_volar_mappings(
124
- source: string,
125
- filename: string,
126
- options?: VolarCompileOptions,
127
- ): VolarMappingsResult;