@danielx/civet 0.5.33 → 0.5.35

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/dist/main.mjs CHANGED
@@ -657,6 +657,7 @@ ${input.slice(result.pos)}
657
657
  FromClause,
658
658
  TypeAndImportSpecifier,
659
659
  ImportSpecifier,
660
+ ImportAsToken,
660
661
  ModuleExportName,
661
662
  ModuleSpecifier,
662
663
  UnprocessedModuleSpecifier,
@@ -879,6 +880,9 @@ ${input.slice(result.pos)}
879
880
  TypeBinaryOp,
880
881
  FunctionType,
881
882
  TypeArguments,
883
+ InlineTypeArguments,
884
+ InlineTypeArgument,
885
+ InlineTypeArgumentDelimiter,
882
886
  CompactTypeArguments,
883
887
  TypeArgument,
884
888
  TypeArgumentDelimiter,
@@ -922,6 +926,7 @@ ${input.slice(result.pos)}
922
926
  CoffeeLineContinuationEnabled,
923
927
  CoffeeNotEnabled,
924
928
  CoffeeOfEnabled,
929
+ CoffeePrototypeEnabled,
925
930
  Reset,
926
931
  Init,
927
932
  Indent,
@@ -1346,12 +1351,13 @@ ${input.slice(result.pos)}
1346
1351
  }
1347
1352
  }
1348
1353
  var Arguments$0 = ExplicitArguments;
1349
- var Arguments$1 = $TS($S(ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1350
- var open = $2;
1351
- var ws = $3;
1352
- var args = $4;
1353
- var close = $5;
1354
- return [open, module.insertTrimmingSpace(ws, ""), args, close];
1354
+ var Arguments$1 = $TS($S($E($S(InlineTypeArguments, $N($S(__, ImplementsToken)))), ApplicationStart, InsertOpenParen, $Q(_), ArgumentList, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
1355
+ var ta = $1;
1356
+ var open = $3;
1357
+ var ws = $4;
1358
+ var args = $5;
1359
+ var close = $6;
1360
+ return [ta?.[0], open, module.insertTrimmingSpace(ws, ""), args, close];
1355
1361
  });
1356
1362
  function Arguments(state) {
1357
1363
  let eventData;
@@ -3258,9 +3264,9 @@ ${input.slice(result.pos)}
3258
3264
  children
3259
3265
  };
3260
3266
  });
3261
- var PropertyAccess$1 = $TS($S(DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2) {
3262
- var p = $1;
3263
- var id = $2;
3267
+ var PropertyAccess$1 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2, $3) {
3268
+ var p = $2;
3269
+ var id = $3;
3264
3270
  if (id) {
3265
3271
  p.token = ".prototype.";
3266
3272
  return [p, id];
@@ -7497,7 +7503,7 @@ ${input.slice(result.pos)}
7497
7503
  declaration = {
7498
7504
  type: "Declaration",
7499
7505
  children: ["let ", ...startRefDec, ...endRefDec, counterRef, " = ", varRef2, " = ", startRef, ...ascDec],
7500
- names: []
7506
+ names: varRef2.names
7501
7507
  };
7502
7508
  blockPrefix.push(["", {
7503
7509
  type: "AssignmentExpression",
@@ -7628,11 +7634,12 @@ ${input.slice(result.pos)}
7628
7634
  var CoffeeForDeclaration$0 = $TS($S($E($S(__, $EXPECT($L78, fail, 'CoffeeForDeclaration "own"'), NonIdContinue)), ForBinding), function($skip, $loc, $0, $1, $2) {
7629
7635
  var own = $1;
7630
7636
  var binding = $2;
7631
- if (own) {
7632
- binding.own = true;
7633
- }
7634
- binding.type = "AssignmentExpression";
7635
- return binding;
7637
+ return {
7638
+ type: "AssignmentExpression",
7639
+ own: Boolean(own),
7640
+ children: [$2],
7641
+ names: $2.names
7642
+ };
7636
7643
  });
7637
7644
  function CoffeeForDeclaration(state) {
7638
7645
  let eventData;
@@ -8656,8 +8663,8 @@ ${input.slice(result.pos)}
8656
8663
  return result;
8657
8664
  }
8658
8665
  }
8659
- var NameSpaceImport$0 = $TS($S(Star, __, As, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8660
- var binding = $5;
8666
+ var NameSpaceImport$0 = $TS($S(Star, ImportAsToken, __, ImportedBinding), function($skip, $loc, $0, $1, $2, $3, $4) {
8667
+ var binding = $4;
8661
8668
  return {
8662
8669
  type: "Declaration",
8663
8670
  children: $0,
@@ -8767,8 +8774,8 @@ ${input.slice(result.pos)}
8767
8774
  return result;
8768
8775
  }
8769
8776
  }
8770
- var ImportSpecifier$0 = $TS($S(__, ModuleExportName, __, As, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
8771
- var binding = $6;
8777
+ var ImportSpecifier$0 = $TS($S(__, ModuleExportName, ImportAsToken, __, ImportedBinding, ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
8778
+ var binding = $5;
8772
8779
  return {
8773
8780
  binding,
8774
8781
  children: $0
@@ -8803,6 +8810,44 @@ ${input.slice(result.pos)}
8803
8810
  return result;
8804
8811
  }
8805
8812
  }
8813
+ var ImportAsToken$0 = $S(__, As);
8814
+ var ImportAsToken$1 = $TS($S(Loc, __, Colon, $E($EXPECT($L4, fail, 'ImportAsToken " "'))), function($skip, $loc, $0, $1, $2, $3, $4) {
8815
+ var l = $1;
8816
+ var ws = $2;
8817
+ var c = $3;
8818
+ const children = [
8819
+ ...ws,
8820
+ { ...c, token: "as " }
8821
+ ];
8822
+ if (!ws.length) {
8823
+ children.unshift({ $loc: l.$loc, token: " " });
8824
+ }
8825
+ return {
8826
+ children
8827
+ };
8828
+ });
8829
+ function ImportAsToken(state) {
8830
+ let eventData;
8831
+ if (state.events) {
8832
+ const result = state.events.enter?.("ImportAsToken", state);
8833
+ if (result) {
8834
+ if (result.cache)
8835
+ return result.cache;
8836
+ eventData = result.data;
8837
+ }
8838
+ }
8839
+ if (state.tokenize) {
8840
+ const result = $TOKEN("ImportAsToken", state, ImportAsToken$0(state) || ImportAsToken$1(state));
8841
+ if (state.events)
8842
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8843
+ return result;
8844
+ } else {
8845
+ const result = ImportAsToken$0(state) || ImportAsToken$1(state);
8846
+ if (state.events)
8847
+ state.events.exit?.("ImportAsToken", state, result, eventData);
8848
+ return result;
8849
+ }
8850
+ }
8806
8851
  var ModuleExportName$0 = StringLiteral;
8807
8852
  var ModuleExportName$1 = IdentifierName;
8808
8853
  function ModuleExportName(state) {
@@ -14831,6 +14876,78 @@ ${input.slice(result.pos)}
14831
14876
  return result;
14832
14877
  }
14833
14878
  }
14879
+ var InlineTypeArguments$0 = $TS($S($Q(_), $EXPECT($L120, fail, 'InlineTypeArguments "<"'), $P(InlineTypeArgument), $Q(_), $EXPECT($L25, fail, 'InlineTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
14880
+ return { ts: true, children: $0 };
14881
+ });
14882
+ function InlineTypeArguments(state) {
14883
+ let eventData;
14884
+ if (state.events) {
14885
+ const result = state.events.enter?.("InlineTypeArguments", state);
14886
+ if (result) {
14887
+ if (result.cache)
14888
+ return result.cache;
14889
+ eventData = result.data;
14890
+ }
14891
+ }
14892
+ if (state.tokenize) {
14893
+ const result = $TOKEN("InlineTypeArguments", state, InlineTypeArguments$0(state));
14894
+ if (state.events)
14895
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14896
+ return result;
14897
+ } else {
14898
+ const result = InlineTypeArguments$0(state);
14899
+ if (state.events)
14900
+ state.events.exit?.("InlineTypeArguments", state, result, eventData);
14901
+ return result;
14902
+ }
14903
+ }
14904
+ var InlineTypeArgument$0 = $S($Q(_), Type, InlineTypeArgumentDelimiter);
14905
+ function InlineTypeArgument(state) {
14906
+ let eventData;
14907
+ if (state.events) {
14908
+ const result = state.events.enter?.("InlineTypeArgument", state);
14909
+ if (result) {
14910
+ if (result.cache)
14911
+ return result.cache;
14912
+ eventData = result.data;
14913
+ }
14914
+ }
14915
+ if (state.tokenize) {
14916
+ const result = $TOKEN("InlineTypeArgument", state, InlineTypeArgument$0(state));
14917
+ if (state.events)
14918
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14919
+ return result;
14920
+ } else {
14921
+ const result = InlineTypeArgument$0(state);
14922
+ if (state.events)
14923
+ state.events.exit?.("InlineTypeArgument", state, result, eventData);
14924
+ return result;
14925
+ }
14926
+ }
14927
+ var InlineTypeArgumentDelimiter$0 = $S($Q(_), Comma);
14928
+ var InlineTypeArgumentDelimiter$1 = $Y($S($Q(_), $EXPECT($L25, fail, 'InlineTypeArgumentDelimiter ">"')));
14929
+ function InlineTypeArgumentDelimiter(state) {
14930
+ let eventData;
14931
+ if (state.events) {
14932
+ const result = state.events.enter?.("InlineTypeArgumentDelimiter", state);
14933
+ if (result) {
14934
+ if (result.cache)
14935
+ return result.cache;
14936
+ eventData = result.data;
14937
+ }
14938
+ }
14939
+ if (state.tokenize) {
14940
+ const result = $TOKEN("InlineTypeArgumentDelimiter", state, InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state));
14941
+ if (state.events)
14942
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14943
+ return result;
14944
+ } else {
14945
+ const result = InlineTypeArgumentDelimiter$0(state) || InlineTypeArgumentDelimiter$1(state);
14946
+ if (state.events)
14947
+ state.events.exit?.("InlineTypeArgumentDelimiter", state, result, eventData);
14948
+ return result;
14949
+ }
14950
+ }
14834
14951
  var CompactTypeArguments$0 = $TS($S($EXPECT($L120, fail, 'CompactTypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L25, fail, 'CompactTypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
14835
14952
  return { ts: true, children: $0 };
14836
14953
  });
@@ -15940,6 +16057,33 @@ ${input.slice(result.pos)}
15940
16057
  return result;
15941
16058
  }
15942
16059
  }
16060
+ var CoffeePrototypeEnabled$0 = $TV($EXPECT($L0, fail, 'CoffeePrototypeEnabled ""'), function($skip, $loc, $0, $1) {
16061
+ if (module.config.coffeePrototype)
16062
+ return;
16063
+ return $skip;
16064
+ });
16065
+ function CoffeePrototypeEnabled(state) {
16066
+ let eventData;
16067
+ if (state.events) {
16068
+ const result = state.events.enter?.("CoffeePrototypeEnabled", state);
16069
+ if (result) {
16070
+ if (result.cache)
16071
+ return result.cache;
16072
+ eventData = result.data;
16073
+ }
16074
+ }
16075
+ if (state.tokenize) {
16076
+ const result = $TOKEN("CoffeePrototypeEnabled", state, CoffeePrototypeEnabled$0(state));
16077
+ if (state.events)
16078
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16079
+ return result;
16080
+ } else {
16081
+ const result = CoffeePrototypeEnabled$0(state);
16082
+ if (state.events)
16083
+ state.events.exit?.("CoffeePrototypeEnabled", state, result, eventData);
16084
+ return result;
16085
+ }
16086
+ }
15943
16087
  var Reset$0 = $TV($EXPECT($L0, fail, 'Reset ""'), function($skip, $loc, $0, $1) {
15944
16088
  module.indentLevels = [{
15945
16089
  level: 0,
@@ -15970,6 +16114,7 @@ ${input.slice(result.pos)}
15970
16114
  coffeeLineContinuation: false,
15971
16115
  coffeeNot: false,
15972
16116
  coffeeOf: false,
16117
+ coffeePrototype: false,
15973
16118
  implicitReturns: true,
15974
16119
  react: false,
15975
16120
  solid: false,
@@ -16124,6 +16269,7 @@ ${input.slice(result.pos)}
16124
16269
  this.coffeeLineContinuation = true;
16125
16270
  this.coffeeNot = true;
16126
16271
  this.coffeeOf = true;
16272
+ this.coffeePrototype = true;
16127
16273
  } else {
16128
16274
  this.autoVar = false;
16129
16275
  this.coffeeBinaryExistential = false;
@@ -16138,6 +16284,7 @@ ${input.slice(result.pos)}
16138
16284
  this.coffeeLineContinuation = false;
16139
16285
  this.coffeeNot = false;
16140
16286
  this.coffeeOf = false;
16287
+ this.coffeePrototype = false;
16141
16288
  }
16142
16289
  }
16143
16290
  });
@@ -16275,7 +16422,7 @@ ${input.slice(result.pos)}
16275
16422
  id: "results"
16276
16423
  };
16277
16424
  insertPush(exp.block, resultsRef);
16278
- exp.children = ["(", resultsRef, "=>{", ...exp.children, "; return ", resultsRef, "})([])"];
16425
+ exp.children = ["(()=>{const ", resultsRef, "=[];", ...exp.children, "; return ", resultsRef, "})()"];
16279
16426
  }
16280
16427
  function wrapIterationReturningResults(statement, outerRef) {
16281
16428
  const resultsRef = {
@@ -17876,11 +18023,17 @@ makeCache = function() {
17876
18023
  };
17877
18024
  return events;
17878
18025
  };
17879
- var main_default = { parse, generate: generate_default, util: util_exports, compile };
18026
+ var isCompileError = function(err) {
18027
+ return err instanceof Error && [err.message, err.name, err.filename, err.line, err.column, err.offset].every(function(value) {
18028
+ return value !== void 0;
18029
+ });
18030
+ };
18031
+ var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
17880
18032
  export {
17881
18033
  compile,
17882
18034
  main_default as default,
17883
18035
  generate_default as generate,
18036
+ isCompileError,
17884
18037
  parse,
17885
18038
  util_exports as util
17886
18039
  };
package/dist/types.d.ts CHANGED
@@ -16,6 +16,17 @@ declare module "@danielx/civet" {
16
16
  }
17
17
  }
18
18
 
19
+ // TODO: Import ParseError class from Hera
20
+ export type ParseError = {
21
+ message: string
22
+ name: string
23
+ filename: string
24
+ line: number
25
+ column: number
26
+ offset: number
27
+ }
28
+ export function isCompileError(err: any): err is ParseError
29
+
19
30
  export function compile<T extends CompileOptions>(source: string, options?: T): T extends { sourceMap: true } ? {
20
31
  code: string,
21
32
  sourceMap: SourceMap,
@@ -25,6 +36,7 @@ declare module "@danielx/civet" {
25
36
 
26
37
  const Civet: {
27
38
  compile: typeof compile
39
+ isCompileError: typeof isCompileError
28
40
  parse: typeof parse
29
41
  generate: typeof generate
30
42
  util: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.33",
3
+ "version": "0.5.35",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",
@@ -10,7 +10,10 @@
10
10
  "require": "./dist/main.js"
11
11
  },
12
12
  "./esm": "./dist/esm.mjs",
13
- "./esbuild-plugin": "./dist/esbuild-plugin.js"
13
+ "./esbuild-plugin": "./dist/esbuild-plugin.js",
14
+ "./register": "./register.js",
15
+ "./*": "./*",
16
+ "./dist/*": "./dist/*"
14
17
  },
15
18
  "types": "dist/types.d.ts",
16
19
  "bin": {