@cilix/lightjs 0.0.12 → 0.0.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 (3) hide show
  1. package/core.js +28 -11
  2. package/index.js +16 -2
  3. package/package.json +1 -1
package/core.js CHANGED
@@ -385,8 +385,6 @@ module.exports = (config, fs, path) => {
385
385
  return c == '\n' || c == '\r'
386
386
  }
387
387
 
388
- // amazing
389
- // https://stackoverflow.com/a/32567789
390
388
  function is_letter (c) {
391
389
  return c.toLowerCase() != c.toUpperCase();
392
390
  }
@@ -591,8 +589,21 @@ module.exports = (config, fs, path) => {
591
589
  });
592
590
  }
593
591
  text = lines.join('\n');
592
+ /* TODO - error reporting within an interpolation is
593
+ * bad (incorrect token position) due to newline magic above */
594
+ tokens.push({ type: 'string', pos: offs + cursor, file: file });
595
+ let chunks = break_into_chunks(text, cursor);
596
+ if (chunks.length > 1) {
597
+ chunks.forEach(function(c) {
598
+ tokens.push(c);
599
+ });
600
+ } else {
601
+ tokens.push({ type: 'chunk', data: text, pos: offs + cursor, file: file })
602
+ }
603
+ /*
594
604
  tokens.push({ type: 'string', pos: offs + cursor, file: file });
595
605
  tokens.push({ type: 'chunk', data: text, pos: offs + cursor, file: file })
606
+ */
596
607
  cursor = i;
597
608
  continue;
598
609
  } else if (c === '"' || c === "'") {
@@ -706,8 +717,9 @@ module.exports = (config, fs, path) => {
706
717
  return false;
707
718
  }
708
719
 
709
- function peek(t) {
710
- if (tok.type === t) {
720
+ function peek(t, forward) {
721
+ const tk = forward ? tokens[cursor + forward] : tok;
722
+ if (tk.type === t) {
711
723
  return true;
712
724
  }
713
725
  return false;
@@ -1008,7 +1020,6 @@ module.exports = (config, fs, path) => {
1008
1020
  let handler;
1009
1021
  let evt;
1010
1022
  if (accept('on')) {
1011
- console.log('YEAHHHHH')
1012
1023
  expect(":");
1013
1024
  evt = tok.data;
1014
1025
  } else {
@@ -1188,6 +1199,10 @@ module.exports = (config, fs, path) => {
1188
1199
  parent = current;
1189
1200
  }
1190
1201
 
1202
+ function isAssignment() {
1203
+ return peek('let') || (peek('ident') && peek(':', 1));
1204
+ }
1205
+
1191
1206
  function parse_tag_list() {
1192
1207
  if (accept("if")) {
1193
1208
  parse_if_statement();
@@ -1222,6 +1237,9 @@ module.exports = (config, fs, path) => {
1222
1237
  } else if (accept("when")) {
1223
1238
  parse_when_statement();
1224
1239
  parse_tag_list();
1240
+ } else if (parse_state.in_tag && isAssignment()) {
1241
+ parse_assignment();
1242
+ parse_tag_list();
1225
1243
  } else if (peek("ident")) {
1226
1244
  parse_tag();
1227
1245
  parse_tag_list();
@@ -1233,9 +1251,6 @@ module.exports = (config, fs, path) => {
1233
1251
  ast_node('yield', { pos: tok.pos, file: tok.file });
1234
1252
  next();
1235
1253
  parse_tag_list();
1236
- } else if (parse_state.in_tag && (peek('global') || peek('const') || peek('let'))) {
1237
- parse_assignment();
1238
- parse_tag_list();
1239
1254
  } else if (parse_state.in_tag && peek('js_context')) {
1240
1255
  includeRuntime = true;
1241
1256
  parent.js = tok.data;
@@ -1304,7 +1319,9 @@ module.exports = (config, fs, path) => {
1304
1319
 
1305
1320
  function parse_assignment () {
1306
1321
  const global = tok.data === 'global';
1307
- next();
1322
+ if (peek('global') || peek('let')) {
1323
+ next();
1324
+ }
1308
1325
  let dst = { data: tok.data, pos: tok.pos, file: tok.file };
1309
1326
  expect('ident');
1310
1327
  if (!accept("=") && !accept(':')) {
@@ -1375,12 +1392,12 @@ module.exports = (config, fs, path) => {
1375
1392
  pos: pos,
1376
1393
  file: file
1377
1394
  });
1395
+ } else if (isAssignment() || peek('global')) {
1396
+ parse_assignment();
1378
1397
  } else if (tok.type === "ident") {
1379
1398
  parse_tag_list();
1380
1399
  } else if (peek("tag")) {
1381
1400
  parse_custom_tag();
1382
- } else if (peek('const') || peek('let') || peek('global')) {
1383
- parse_assignment();
1384
1401
  } else if (peek('js_context')) {
1385
1402
  includeRuntime = true;
1386
1403
  ast_node('js', { js: tok.data, pos: tok.pos, file: tok.file });
package/index.js CHANGED
@@ -236,7 +236,14 @@ function matchRoute (istr, mstr) {
236
236
  if (last[last.length - 1] !== '*') {
237
237
  return null;
238
238
  }
239
- } else if (p0.length !== p1.length) return null;
239
+ } else if (p0.length === p1.length - 1) {
240
+ const last = p1[p1.length - 1];
241
+ if (last[last.length - 1] !== '?') {
242
+ return null;
243
+ }
244
+ } else if (p0.length !== p1.length) {
245
+ return null;
246
+ }
240
247
  for (let i = 0; i < p1.length; i++) {
241
248
  const p = p1[i];
242
249
  if (p[0] !== ':') {
@@ -249,7 +256,13 @@ function matchRoute (istr, mstr) {
249
256
  out[p.slice(1, -1)] += `/${p0[j]}`;
250
257
  }
251
258
  } else {
252
- out[p.slice(1)] = p0[i];
259
+ if (p[p.length - 1] === '?') {
260
+ if (p0[i]) {
261
+ out[p.slice(1, -1)] = p0[i];
262
+ }
263
+ } else {
264
+ out[p.slice(1)] = p0[i];
265
+ }
253
266
  }
254
267
  }
255
268
  return out;
@@ -329,6 +342,7 @@ Light.router = function (opts) {
329
342
  if (!matchedRoute) {
330
343
  if (next) {
331
344
  next();
345
+ return;
332
346
  } else {
333
347
  res.writeHead(404, { 'Content-type': 'text/html; charset=utf-8' });
334
348
  res.end('<h1>404 - Not Found</h1>');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cilix/lightjs",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "A new kind of JavaScript framework",
5
5
  "main": "index.js",
6
6
  "scripts": {