Skip to content

Commit cd1073f

Browse files
authored
feat: Editor support for #ripple.server (#804)
1 parent 128e690 commit cd1073f

File tree

6 files changed

+23
-31
lines changed

6 files changed

+23
-31
lines changed

.changeset/early-pots-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ripple': patch
3+
---
4+
5+
Editor support for #ripple.server

packages/ripple/src/compiler/identifier-utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ export const IDENTIFIER_OBFUSCATION_PREFIX = '_$_';
22
export const RIPPLE_NAMESPACE_IDENTIFIER =
33
IDENTIFIER_OBFUSCATION_PREFIX + encode_utf16_char('#') + 'ripple';
44
export const STYLE_IDENTIFIER = IDENTIFIER_OBFUSCATION_PREFIX + encode_utf16_char('#') + 'style';
5-
export const SERVER_IDENTIFIER = IDENTIFIER_OBFUSCATION_PREFIX + encode_utf16_char('#') + 'server';
5+
export const SERVER_IDENTIFIER =
6+
IDENTIFIER_OBFUSCATION_PREFIX +
7+
encode_utf16_char('#') +
8+
'ripple' +
9+
encode_utf16_char('.') +
10+
'server';
611
export const CSS_HASH_IDENTIFIER = IDENTIFIER_OBFUSCATION_PREFIX + 'hash';
712

813
const DECODE_UTF16_REGEX = /_u([0-9a-fA-F]{4})_/g;

packages/ripple/src/compiler/phases/3-transform/client/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,9 @@ const visitors = {
541541
},
542542

543543
ServerIdentifier(node, context) {
544-
const id = b.id(SERVER_IDENTIFIER);
544+
const id = b.id(SERVER_IDENTIFIER, /** @type {AST.NodeWithLocation} */ (node));
545545
id.metadata.source_name = '#ripple.server';
546-
return { ...node, ...id };
546+
return id;
547547
},
548548

549549
StyleIdentifier(node, context) {
@@ -2716,8 +2716,10 @@ const visitors = {
27162716
);
27172717
value.loc = node.loc;
27182718

2719-
const server_identifier = b.id(SERVER_IDENTIFIER);
2720-
server_identifier.loc = node.loc;
2719+
const server_identifier = b.id(
2720+
SERVER_IDENTIFIER,
2721+
slice_loc_info(/** @type {AST.NodeWithLocation} */ (node), 0, '#ripple.server'.length),
2722+
);
27212723
// Add source_name to properly map longer generated back to '#ripple.server'
27222724
server_identifier.metadata.source_name = '#ripple.server';
27232725

packages/ripple/src/compiler/phases/3-transform/segments.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -422,35 +422,13 @@ export function convert_source_map_to_mappings(
422422
loc: node.loc,
423423
metadata: {},
424424
};
425-
426-
if (node.metadata.source_name === '#ripple') {
427-
// Suppress the private-identifier parse diagnostic while the user is
428-
// still typing a namespace access like `#ripple.` for completions.
429-
token.metadata.suppressedDiagnostics = [18016];
430-
}
431-
432-
if (
433-
node.metadata.source_name === '#ripple.server' ||
434-
node.metadata.source_name === '#ripple.style'
435-
) {
436-
// Let TextMate own the coloring for these namespace forms.
437-
// Their dedicated AST nodes otherwise cause semantic tokens to repaint
438-
// the full '#ripple.server' / '#ripple.style' span after TS attaches.
439-
token.mappingData = { ...mapping_data, semantic: false };
440-
}
441425
} else {
442426
token = {
443427
source: node.name,
444428
generated: node.name,
445429
loc: node.loc,
446430
metadata: {},
447431
};
448-
if (node.name === '#ripple') {
449-
// Suppress the private-identifier parse diagnostic while the user is
450-
// still typing a namespace access like `#ripple.` for completions.
451-
token.metadata.suppressedDiagnostics = [18016];
452-
}
453-
// No transformation - source and generated names are the same
454432
}
455433

456434
if (node.metadata?.is_component) {

packages/ripple/tests/client/compiler/compiler.basic.test.ripple

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,7 @@ export component App() {
519519
});
520520

521521
it('parses bare #ripple in loose mode for autocomplete recovery', () => {
522-
const source = `
523-
export component App() {
522+
const source = `export component App() {
524523
#ripple
525524
}
526525
`;
@@ -536,6 +535,6 @@ export component App() {
536535
mapping.lengths[0] === '#ripple'.length,
537536
);
538537

539-
expect(mapping?.data.customData.suppressedDiagnostics).toContain(18016);
538+
expect(mapping).toBeDefined();
540539
});
541540
});

packages/ripple/types/index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ export function bindFiles<V extends FileList>(
545545
setter?: SetFunction<V>,
546546
): (node: HTMLInputElement) => void;
547547

548+
type ServerBlock = {};
549+
548550
export interface RippleNamespace {
549551
array: RippleArrayCallable;
550552
object: RippleObjectCallable;
@@ -559,7 +561,8 @@ export interface RippleNamespace {
559561
untrack: typeof untrack;
560562
track: typeof track;
561563
trackSplit: typeof trackSplit;
562-
style: Record<string, string>; // Placeholder for style-related runtime class names (e.g., #ripple.style.someClass)
564+
style: Record<string, string>;
565+
server: ServerBlock;
563566
}
564567

565568
export declare const ripple_namespace: RippleNamespace;

0 commit comments

Comments
 (0)