ripple 0.2.189 → 0.2.191

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.
@@ -16,7 +16,7 @@ interface BaseNodeMetaData {
16
16
  scoped?: boolean;
17
17
  path: AST.Node[];
18
18
  has_template?: boolean;
19
- original_name?: string;
19
+ source_name?: string | '#Map' | '#Set' | '#server' | '#style';
20
20
  is_capitalized?: boolean;
21
21
  has_await?: boolean;
22
22
  commentContainerId?: number;
@@ -78,11 +78,7 @@ declare module 'estree' {
78
78
  implements?: AST.TSClassImplements[];
79
79
  }
80
80
 
81
- interface Identifier extends TrackedNode {
82
- metadata: BaseNode['metadata'] & {
83
- tracked_shorthand?: '#Map' | '#Set';
84
- };
85
- }
81
+ interface Identifier extends TrackedNode {}
86
82
 
87
83
  interface MemberExpression extends AST.TrackedNode {}
88
84
 
@@ -98,7 +94,9 @@ declare module 'estree' {
98
94
  Element: Element;
99
95
  Text: TextNode;
100
96
  ServerBlock: ServerBlock;
97
+ ServerBlockStatement: ServerBlockStatement;
101
98
  ServerIdentifier: ServerIdentifier;
99
+ StyleIdentifier: StyleIdentifier;
102
100
  TrackedExpression: TrackedExpression;
103
101
  Attribute: Attribute;
104
102
  RefAttribute: RefAttribute;
@@ -112,6 +110,8 @@ declare module 'estree' {
112
110
  TrackedMapExpression: TrackedMapExpression;
113
111
  TrackedSetExpression: TrackedSetExpression;
114
112
  TrackedExpression: TrackedExpression;
113
+ StyleIdentifier: StyleIdentifier;
114
+ ServerIdentifier: ServerIdentifier;
115
115
  Text: TextNode;
116
116
  }
117
117
 
@@ -143,15 +143,17 @@ declare module 'estree' {
143
143
  type: 'ServerIdentifier';
144
144
  }
145
145
 
146
+ interface StyleIdentifier extends AST.BaseNode {
147
+ type: 'StyleIdentifier';
148
+ }
149
+
146
150
  interface ImportDeclaration {
147
151
  importKind: TSESTree.ImportDeclaration['importKind'];
148
152
  }
149
153
  interface ImportSpecifier {
150
154
  importKind: TSESTree.ImportSpecifier['importKind'];
151
155
  }
152
- interface ExportNamedDeclaration
153
- // doesn't seem we're using parent and assertions, removing to avoid builders errors
154
- extends Omit<TSESTree.ExportNamedDeclaration, 'exportKind' | 'parent' | 'assertions'> {
156
+ interface ExportNamedDeclaration {
155
157
  exportKind: TSESTree.ExportNamedDeclaration['exportKind'];
156
158
  }
157
159
 
@@ -200,6 +202,9 @@ declare module 'estree' {
200
202
  css: CSS.StyleSheet | null;
201
203
  metadata: BaseNodeMetaData & {
202
204
  inherited_css?: boolean;
205
+ topScopedClasses?: TopScopedClasses;
206
+ styleClasses?: StyleClasses;
207
+ styleIdentifierPresent?: boolean;
203
208
  };
204
209
  default: boolean;
205
210
  }
@@ -240,14 +245,6 @@ declare module 'estree' {
240
245
  selector: CSS.ClassSelector;
241
246
  }
242
247
  >;
243
- topScopedClasses: Map<
244
- string,
245
- {
246
- start: number;
247
- end: number;
248
- selector: CSS.ClassSelector;
249
- }
250
- >;
251
248
  hash: string;
252
249
  };
253
250
  };
@@ -271,9 +268,13 @@ declare module 'estree' {
271
268
  loc?: AST.SourceLocation;
272
269
  }
273
270
 
271
+ interface ServerBlockStatement extends Omit<BlockStatement, 'body'> {
272
+ body: (AST.Statement | AST.ExportNamedDeclaration)[];
273
+ }
274
+
274
275
  interface ServerBlock extends AST.BaseNode {
275
276
  type: 'ServerBlock';
276
- body: BlockStatement;
277
+ body: ServerBlockStatement;
277
278
  metadata: BaseNodeMetaData & {
278
279
  exports: string[];
279
280
  };
@@ -530,6 +531,10 @@ declare module 'estree-jsx' {
530
531
  shorthand: boolean;
531
532
  }
532
533
 
534
+ interface JSXIdentifier {
535
+ tracked?: boolean;
536
+ }
537
+
533
538
  interface JSXEmptyExpression {
534
539
  loc: AST.SourceLocation;
535
540
  innerComments?: AST.Comment[];
@@ -964,6 +969,9 @@ export interface AnalysisResult {
964
969
  scopes: Map<AST.Node, ScopeInterface>;
965
970
  scope: ScopeInterface;
966
971
  component_metadata: Array<{ id: string; async: boolean }>;
972
+ metadata: {
973
+ serverIdentifierPresent: boolean;
974
+ };
967
975
  }
968
976
 
969
977
  /**
@@ -1111,6 +1119,8 @@ export interface BaseState {
1111
1119
  /** For utils */
1112
1120
  scope: ScopeInterface;
1113
1121
  scopes: Map<AST.Node | AST.Node[], ScopeInterface>;
1122
+ serverIdentifierPresent: boolean;
1123
+ inside_server_block: boolean;
1114
1124
  inside_head?: boolean;
1115
1125
 
1116
1126
  /** Common For All */
@@ -1129,20 +1139,21 @@ export interface AnalysisState extends BaseState {
1129
1139
  };
1130
1140
  elements?: AST.Element[];
1131
1141
  function_depth?: number;
1132
- inside_server_block?: boolean;
1133
1142
  loose?: boolean;
1134
- metadata: BaseStateMetaData;
1143
+ metadata: BaseStateMetaData & {
1144
+ styleClasses?: StyleClasses;
1145
+ };
1135
1146
  }
1136
1147
 
1137
1148
  export interface TransformServerState extends BaseState {
1138
- imports: Set<string>;
1149
+ imports: Set<string | AST.ImportDeclaration>;
1139
1150
  init: Array<AST.Statement> | null;
1140
1151
  stylesheets: AST.CSS.StyleSheet[];
1141
1152
  component_metadata: AnalysisResult['component_metadata'];
1142
- inside_server_block: boolean;
1143
1153
  filename: string;
1144
1154
  metadata: BaseStateMetaData;
1145
1155
  namespace: NameSpace;
1156
+ server_block_locals: AST.VariableDeclaration[];
1146
1157
  }
1147
1158
 
1148
1159
  type UpdateList = Array<{
@@ -1159,7 +1170,8 @@ export interface TransformClientState extends BaseState {
1159
1170
  final: Array<AST.Statement> | null;
1160
1171
  flush_node: ((is_controlled?: boolean) => AST.Identifier) | null;
1161
1172
  hoisted: Array<AST.Statement>;
1162
- imports: Set<string>;
1173
+ imports: Set<string | AST.ImportDeclaration>;
1174
+ server_block_locals: AST.VariableDeclaration[];
1163
1175
  init: Array<AST.Statement> | null;
1164
1176
  metadata: BaseStateMetaData;
1165
1177
  namespace: NameSpace;
@@ -1206,3 +1218,14 @@ export type VisitorClientContext = TransformClientContext & { root?: boolean };
1206
1218
  export interface DelegatedEventResult {
1207
1219
  function?: AST.FunctionExpression | AST.FunctionDeclaration | AST.ArrowFunctionExpression;
1208
1220
  }
1221
+
1222
+ export type TopScopedClasses = Map<
1223
+ string,
1224
+ {
1225
+ start: number;
1226
+ end: number;
1227
+ selector: AST.CSS.ClassSelector;
1228
+ }
1229
+ >;
1230
+
1231
+ export type StyleClasses = Map<string, AST.MemberExpression['property']>;
@@ -499,6 +499,10 @@ export namespace Parse {
499
499
  potentialArrowAt: number;
500
500
  /** Potential arrow in for-await position */
501
501
  potentialArrowInForAwait: boolean;
502
+ /** Previous token type */
503
+ preToken: TokenType | null;
504
+ /** Previous token value */
505
+ preValue: string | number | RegExp | bigint | null;
502
506
  /** Private name stack for class private fields validation */
503
507
  privateNameStack: Array<{ declared: Record<string, string>; used: Array<AST.Node> }>;
504
508
  /** Undefined exports for module validation */
@@ -920,6 +924,7 @@ export namespace Parse {
920
924
  forNew?: boolean,
921
925
  ):
922
926
  | AST.ServerIdentifier
927
+ | AST.StyleIdentifier
923
928
  | AST.TrackedExpression
924
929
  | AST.TrackedMapExpression
925
930
  | AST.TrackedSetExpression
@@ -227,7 +227,7 @@ export function is_top_level_await(context) {
227
227
  * Returns true if context is inside a Component node
228
228
  * @param {CommonContext} context
229
229
  * @param {boolean} [includes_functions=false]
230
- * @returns {boolean}
230
+ * @returns {AST.Component | undefined}
231
231
  */
232
232
  export function is_inside_component(context, includes_functions = false) {
233
233
  for (let i = context.path.length - 1; i >= 0; i -= 1) {
@@ -240,13 +240,13 @@ export function is_inside_component(context, includes_functions = false) {
240
240
  type === 'ArrowFunctionExpression' ||
241
241
  type === 'FunctionDeclaration')
242
242
  ) {
243
- return false;
243
+ return;
244
244
  }
245
245
  if (context_node.type === 'Component') {
246
- return true;
246
+ return context_node;
247
247
  }
248
248
  }
249
- return false;
249
+ return;
250
250
  }
251
251
 
252
252
  /**
@@ -396,16 +396,17 @@ export function object_pattern(properties) {
396
396
  * @param {AST.Expression } key
397
397
  * @param {Value} value
398
398
  * @param {boolean} computed
399
+ * @param {boolean} shorthand
399
400
  * @returns {AST.Property}
400
401
  */
401
- export function prop(kind, key, value, computed = false) {
402
+ export function prop(kind, key, value, computed = false, shorthand = false) {
402
403
  return {
403
404
  type: 'Property',
404
405
  kind,
405
406
  key,
406
407
  value,
407
408
  method: false,
408
- shorthand: false,
409
+ shorthand,
409
410
  computed,
410
411
  metadata: { path: [] },
411
412
  };
@@ -1,5 +1,5 @@
1
1
  import { parse, compile, compile_to_volar_mappings } from 'ripple/compiler';
2
- import { obfuscate_imported } from 'ripple/compiler/internal/import/utils';
2
+ import { obfuscate_identifier } from 'ripple/compiler/internal/identifier/utils';
3
3
  import type * as AST from 'estree';
4
4
 
5
5
  function count_occurrences(string: string, subString: string): number {
@@ -285,15 +285,15 @@ component App() {
285
285
  `;
286
286
  const result = compile_to_volar_mappings(source, 'test.ripple').code;
287
287
 
288
- expect(count_occurrences(result, obfuscate_imported('TrackedArray'))).toBe(2);
288
+ expect(count_occurrences(result, obfuscate_identifier('TrackedArray'))).toBe(2);
289
289
  expect(count_occurrences(result, 'TA')).toBe(1);
290
- expect(count_occurrences(result, obfuscate_imported('TrackedObject'))).toBe(2);
290
+ expect(count_occurrences(result, obfuscate_identifier('TrackedObject'))).toBe(2);
291
291
  expect(count_occurrences(result, 'TO')).toBe(1);
292
- expect(count_occurrences(result, obfuscate_imported('TrackedSet'))).toBe(2);
292
+ expect(count_occurrences(result, obfuscate_identifier('TrackedSet'))).toBe(2);
293
293
  expect(count_occurrences(result, 'TS')).toBe(1);
294
- expect(count_occurrences(result, obfuscate_imported('TrackedMap'))).toBe(2);
294
+ expect(count_occurrences(result, obfuscate_identifier('TrackedMap'))).toBe(2);
295
295
  expect(count_occurrences(result, 'TM')).toBe(1);
296
- expect(count_occurrences(result, obfuscate_imported('createRefKey'))).toBe(2);
296
+ expect(count_occurrences(result, obfuscate_identifier('createRefKey'))).toBe(2);
297
297
  expect(count_occurrences(result, 'crk')).toBe(1);
298
298
  },
299
299
  );
@@ -311,11 +311,11 @@ component App() {
311
311
  `;
312
312
  const result = compile_to_volar_mappings(source, 'test.ripple').code;
313
313
 
314
- expect(count_occurrences(result, obfuscate_imported('TrackedArray'))).toBe(2);
315
- expect(count_occurrences(result, obfuscate_imported('TrackedObject'))).toBe(2);
316
- expect(count_occurrences(result, obfuscate_imported('TrackedSet'))).toBe(2);
317
- expect(count_occurrences(result, obfuscate_imported('TrackedMap'))).toBe(2);
318
- expect(count_occurrences(result, obfuscate_imported('createRefKey'))).toBe(2);
314
+ expect(count_occurrences(result, obfuscate_identifier('TrackedArray'))).toBe(2);
315
+ expect(count_occurrences(result, obfuscate_identifier('TrackedObject'))).toBe(2);
316
+ expect(count_occurrences(result, obfuscate_identifier('TrackedSet'))).toBe(2);
317
+ expect(count_occurrences(result, obfuscate_identifier('TrackedMap'))).toBe(2);
318
+ expect(count_occurrences(result, obfuscate_identifier('createRefKey'))).toBe(2);
319
319
  });
320
320
 
321
321
  it('should not error on having js below markup in the same scope', () => {
package/types/index.d.ts CHANGED
@@ -209,10 +209,10 @@ export type TrackedObjectDeep<T> = T extends
209
209
  ? { [K in keyof T]: TrackedObjectDeep<T[K]> | Tracked<TrackedObjectDeep<T[K]>> }
210
210
  : T | Tracked<T>;
211
211
 
212
- export type TrackedObject<T extends object> = T & {};
212
+ export interface TrackedObject<T extends Object> extends Object {}
213
213
 
214
214
  export interface TrackedObjectConstructor {
215
- new <T extends object>(obj: T): TrackedObject<T>;
215
+ new <T extends Object>(obj: T): TrackedObject<T>;
216
216
  }
217
217
 
218
218
  export const TrackedObject: TrackedObjectConstructor;
@@ -1,51 +0,0 @@
1
- export const IMPORT_OBFUSCATION_PREFIX = '_$_';
2
-
3
- /**
4
- * @param {string} name
5
- * @returns {string}
6
- */
7
- export function obfuscate_imported(name) {
8
- let start = 0;
9
- if (name[0] === name[0].toUpperCase()) {
10
- start = 1;
11
- }
12
- const index = find_next_uppercase(name, start);
13
-
14
- const first_part = name.slice(0, index);
15
- const second_part = name.slice(index);
16
-
17
- return IMPORT_OBFUSCATION_PREFIX + (second_part ? second_part + '__' + first_part : first_part);
18
- }
19
-
20
- /**
21
- * @param {string} name
22
- * @returns {boolean}
23
- */
24
- export function is_imported_obfuscated(name) {
25
- return name.startsWith(IMPORT_OBFUSCATION_PREFIX);
26
- }
27
-
28
- /**
29
- * @param {string} name
30
- * @returns {string}
31
- */
32
- export function deobfuscate_imported(name) {
33
- name = name.replace(IMPORT_OBFUSCATION_PREFIX, '');
34
- const parts = name.split('__');
35
- return (parts[1] ? parts[1] : '') + parts[0];
36
- }
37
-
38
- /**
39
- * Finds the next uppercase character or returns name.length
40
- * @param {string} name
41
- * @param {number} start
42
- * @returns {number}
43
- */
44
- function find_next_uppercase(name, start) {
45
- for (let i = start; i < name.length; i++) {
46
- if (name[i] === name[i].toUpperCase()) {
47
- return i;
48
- }
49
- }
50
- return name.length;
51
- }