ripple 0.3.13 → 0.3.15

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 (70) hide show
  1. package/CHANGELOG.md +35 -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.components.test.rsrx +103 -1
  19. package/tests/client/basic/basic.errors.test.rsrx +1 -1
  20. package/tests/client/basic/basic.styling.test.rsrx +1 -1
  21. package/tests/client/compiler/compiler.assignments.test.rsrx +1 -1
  22. package/tests/client/compiler/compiler.attributes.test.rsrx +1 -1
  23. package/tests/client/compiler/compiler.basic.test.rsrx +51 -14
  24. package/tests/client/compiler/compiler.tracked-access.test.rsrx +1 -1
  25. package/tests/client/compiler/compiler.try-in-function.test.rsrx +1 -1
  26. package/tests/client/compiler/compiler.typescript.test.rsrx +1 -1
  27. package/tests/client/css/global-additional-cases.test.rsrx +1 -1
  28. package/tests/client/css/global-advanced-selectors.test.rsrx +1 -1
  29. package/tests/client/css/global-at-rules.test.rsrx +1 -1
  30. package/tests/client/css/global-basic.test.rsrx +1 -1
  31. package/tests/client/css/global-classes-ids.test.rsrx +1 -1
  32. package/tests/client/css/global-combinators.test.rsrx +1 -1
  33. package/tests/client/css/global-complex-nesting.test.rsrx +1 -1
  34. package/tests/client/css/global-edge-cases.test.rsrx +1 -1
  35. package/tests/client/css/global-keyframes.test.rsrx +1 -1
  36. package/tests/client/css/global-nested.test.rsrx +1 -1
  37. package/tests/client/css/global-pseudo.test.rsrx +1 -1
  38. package/tests/client/css/global-scoping.test.rsrx +1 -1
  39. package/tests/client/css/style-identifier.test.rsrx +1 -1
  40. package/tests/client/return.test.rsrx +1 -1
  41. package/tests/hydration/build-components.js +1 -1
  42. package/tests/server/basic.components.test.rsrx +114 -0
  43. package/tests/server/compiler.test.rsrx +38 -1
  44. package/tests/server/style-identifier.test.rsrx +1 -1
  45. package/tests/setup-server.js +1 -1
  46. package/tests/utils/compiler-compat-config.test.js +1 -1
  47. package/types/index.d.ts +1 -1
  48. package/src/compiler/comment-utils.js +0 -91
  49. package/src/compiler/errors.js +0 -77
  50. package/src/compiler/identifier-utils.js +0 -80
  51. package/src/compiler/index.d.ts +0 -127
  52. package/src/compiler/index.js +0 -89
  53. package/src/compiler/phases/1-parse/index.js +0 -3007
  54. package/src/compiler/phases/1-parse/style.js +0 -704
  55. package/src/compiler/phases/2-analyze/css-analyze.js +0 -160
  56. package/src/compiler/phases/2-analyze/index.js +0 -2208
  57. package/src/compiler/phases/2-analyze/prune.js +0 -1131
  58. package/src/compiler/phases/2-analyze/validation.js +0 -168
  59. package/src/compiler/phases/3-transform/client/index.js +0 -5264
  60. package/src/compiler/phases/3-transform/segments.js +0 -2125
  61. package/src/compiler/phases/3-transform/server/index.js +0 -1749
  62. package/src/compiler/phases/3-transform/stylesheet.js +0 -545
  63. package/src/compiler/scope.js +0 -476
  64. package/src/compiler/source-map-utils.js +0 -358
  65. package/src/compiler/types/acorn.d.ts +0 -11
  66. package/src/compiler/types/estree-jsx.d.ts +0 -11
  67. package/src/compiler/types/estree.d.ts +0 -11
  68. package/src/compiler/types/index.d.ts +0 -1411
  69. package/src/compiler/types/parse.d.ts +0 -1723
  70. package/src/compiler/utils.js +0 -1258
@@ -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;
@@ -1,89 +0,0 @@
1
- /** @import * as AST from 'estree' */
2
-
3
- import { parse as parse_module } from './phases/1-parse/index.js';
4
- import { analyze } from './phases/2-analyze/index.js';
5
- import { transform_client } from './phases/3-transform/client/index.js';
6
- import { transform_server } from './phases/3-transform/server/index.js';
7
- import { convert_source_map_to_mappings } from './phases/3-transform/segments.js';
8
-
9
- /**
10
- * Parse Ripple source code to ESTree AST
11
- * @param {string} source
12
- * @returns {AST.Program}
13
- */
14
- export function parse(source) {
15
- return parse_module(source, undefined, undefined);
16
- }
17
-
18
- /**
19
- * Compile Ripple source code to JS/CSS output
20
- * @param {string} source
21
- * @param {string} filename
22
- * @param {CompileOptions} [options]
23
- * @returns {object}
24
- */
25
- export function compile(source, filename, options = {}) {
26
- const ast = parse_module(source, filename, undefined);
27
- const analysis = analyze(ast, filename, options);
28
- const result =
29
- options.mode === 'server'
30
- ? transform_server(
31
- filename,
32
- source,
33
- analysis,
34
- options?.minify_css ?? false,
35
- options?.dev ?? false,
36
- )
37
- : transform_client(
38
- filename,
39
- source,
40
- analysis,
41
- false,
42
- options?.minify_css ?? false,
43
- options?.hmr ?? false,
44
- );
45
-
46
- return result;
47
- }
48
-
49
- /** @import { PostProcessingChanges, LineOffsets } from './phases/3-transform/client/index.js' */
50
- /** @import { VolarMappingsResult, VolarCompileOptions, CompileOptions, RippleCompileError } from 'ripple/compiler' */
51
-
52
- /**
53
- * Compile Ripple component to Volar virtual code with TypeScript mappings
54
- * @param {string} source
55
- * @param {string} filename
56
- * @param {VolarCompileOptions} [options] - Compiler options
57
- * @returns {VolarMappingsResult} Volar mappings object
58
- */
59
- export function compile_to_volar_mappings(source, filename, options = {}) {
60
- const errors = /** @type {RippleCompileError[]} */ ([]);
61
- const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
62
- const ast = parse_module(source, filename, { ...options, errors, comments });
63
- const analysis = analyze(ast, filename, {
64
- to_ts: true,
65
- loose: !!options?.loose,
66
- errors,
67
- comments,
68
- });
69
- const transformed = transform_client(
70
- filename,
71
- source,
72
- analysis,
73
- true,
74
- options?.minify_css ?? false,
75
- );
76
-
77
- return {
78
- ...convert_source_map_to_mappings(
79
- transformed.ast,
80
- ast,
81
- source,
82
- transformed.js.code,
83
- transformed.js.map,
84
- /** @type {PostProcessingChanges} */ (transformed.js.post_processing_changes),
85
- /** @type {LineOffsets} */ (transformed.js.line_offsets),
86
- ),
87
- errors: transformed.errors,
88
- };
89
- }