ripple 0.2.40 → 0.2.42

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ripple is a TypeScript UI framework for the web",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.40",
6
+ "version": "0.2.42",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index.js",
9
9
  "main": "src/runtime/index.js",
@@ -2,6 +2,7 @@ import * as acorn from 'acorn';
2
2
  import { tsPlugin } from 'acorn-typescript';
3
3
  import { parse_style } from './style.js';
4
4
  import { walk } from 'zimmerframe';
5
+ import { regex_newline_characters } from '../../../utils/patterns.js';
5
6
 
6
7
  const parser = acorn.Parser.extend(tsPlugin({ allowSatisfies: true }), RipplePlugin());
7
8
 
@@ -412,7 +413,9 @@ function RipplePlugin(config) {
412
413
  }
413
414
  } else {
414
415
  if (open.name.name === 'style') {
415
- const start = this.start;
416
+ // jsx_parseOpeningElementAt treats ID selectors (ie. #myid) or type selectors (ie. div) as identifier and read it
417
+ // So backtrack to the end of the <style> tag to make sure everything is included
418
+ const start = open.end;
416
419
  const input = this.input.slice(start);
417
420
  const end = input.indexOf('</style>');
418
421
  const content = input.slice(0, end);
@@ -423,7 +426,13 @@ function RipplePlugin(config) {
423
426
  }
424
427
  component.css = parse_style(content);
425
428
 
426
- this.pos = start + end + 1;
429
+ const newLines = content.match(regex_newline_characters)?.length;
430
+ if (newLines) {
431
+ this.curLine = open.loc.end.line + newLines;
432
+ this.lineStart = start + content.lastIndexOf('\n') + 1;
433
+ }
434
+ this.pos = start + content.length + 1;
435
+
427
436
  this.type = tok.jsxTagStart;
428
437
  this.next();
429
438
  if (this.value === '/') {
@@ -199,6 +199,20 @@ const visitors = {
199
199
  );
200
200
  },
201
201
 
202
+ TSTypeAliasDeclaration(_, context) {
203
+ if (!context.state.to_ts) {
204
+ return b.empty;
205
+ }
206
+ context.next();
207
+ },
208
+
209
+ TSInterfaceDeclaration(_, context) {
210
+ if (!context.state.to_ts) {
211
+ return b.empty;
212
+ }
213
+ context.next();
214
+ },
215
+
202
216
  NewExpression(node, context) {
203
217
  const callee = node.callee;
204
218
  const parent = context.path.at(-1);
@@ -12,6 +12,7 @@ export const regex_whitespaces_strict = /[ \t\n\r\f]+/g;
12
12
 
13
13
  export const regex_only_whitespaces = /^[ \t\n\r\f]+$/;
14
14
 
15
+ export const regex_newline_characters = /\n/g;
15
16
  export const regex_not_newline_characters = /[^\n]/g;
16
17
 
17
18
  export const regex_is_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
@@ -1,5 +1,6 @@
1
1
  import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
2
  import { mount, RippleArray } from 'ripple';
3
+ import { parse } from 'ripple/compiler'
3
4
 
4
5
  describe('compiler success tests', () => {
5
6
  let container;
@@ -20,6 +21,30 @@ describe('compiler success tests', () => {
20
21
  container = null;
21
22
  });
22
23
 
24
+
25
+ it('Parses style content correctly', () => {
26
+ const source = `export component App() {
27
+ <div id="myid" class="myclass">{"Hello World"}</div>
28
+
29
+ <style>#style</style>
30
+ }`;
31
+ const style1 = '.myid {color: green }';
32
+ const style2 = '#myid {color: green }';
33
+ const style3 = 'div {color: green }';
34
+
35
+ let input = source.replace('#style', style1);
36
+ let ast = parse(input);
37
+ expect(ast.body[0].declaration.css.source).toEqual(style1);
38
+
39
+ input = source.replace('#style', style2);
40
+ ast = parse(input);
41
+ expect(ast.body[0].declaration.css.source).toEqual(style2);
42
+
43
+ input = source.replace('#style', style3);
44
+ ast = parse(input);
45
+ expect(ast.body[0].declaration.css.source).toEqual(style3);
46
+ });
47
+
23
48
  it('renders without crashing', () => {
24
49
  component App() {
25
50
  let foo;