@danielx/civet 0.6.50 → 0.6.52

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/browser.js CHANGED
@@ -3883,6 +3883,10 @@ ${input.slice(result.pos)}
3883
3883
  ShortArrowParameters,
3884
3884
  ArrowParameters,
3885
3885
  NonEmptyParameters,
3886
+ ParameterList,
3887
+ NestedParameterList,
3888
+ NestedParameter,
3889
+ Parameter,
3886
3890
  FunctionRestParameter,
3887
3891
  ParameterElement,
3888
3892
  ParameterElementDelimiter,
@@ -4209,6 +4213,7 @@ ${input.slice(result.pos)}
4209
4213
  Case,
4210
4214
  Catch,
4211
4215
  Class,
4216
+ CloseAngleBracket,
4212
4217
  CloseBrace,
4213
4218
  CloseBracket,
4214
4219
  CloseParen,
@@ -4680,7 +4685,7 @@ ${input.slice(result.pos)}
4680
4685
  var $R1 = $R(new RegExp("(as|of|satisfies|then|when|implements|xor|xnor)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
4681
4686
  var $R2 = $R(new RegExp("[0-9]", "suy"));
4682
4687
  var $R3 = $R(new RegExp("[ \\t]", "suy"));
4683
- var $R4 = $R(new RegExp("(?=['\"`])", "suy"));
4688
+ var $R4 = $R(new RegExp("(?=['\"`<])", "suy"));
4684
4689
  var $R5 = $R(new RegExp("(?=[\\/?])", "suy"));
4685
4690
  var $R6 = $R(new RegExp("(?=[\\/\\[{?.!@'\u2019:])", "suy"));
4686
4691
  var $R7 = $R(new RegExp("[)}]", "suy"));
@@ -5328,8 +5333,11 @@ ${input.slice(result.pos)}
5328
5333
  function TrailingDeclaration(ctx, state) {
5329
5334
  return $EVENT(ctx, state, "TrailingDeclaration", TrailingDeclaration$0);
5330
5335
  }
5331
- var FatArrowBody$0 = $T($S($N(EOS), NonPipelinePostfixedExpression, $N(TrailingDeclaration), $N(SemicolonDelimiter)), function(value) {
5332
- var exp = value[1];
5336
+ var FatArrowBody$0 = $TS($S($N(EOS), NonPipelinePostfixedExpression, $N(TrailingDeclaration), $N(SemicolonDelimiter)), function($skip, $loc, $0, $1, $2, $3, $4) {
5337
+ var exp = $2;
5338
+ if (exp.type === "ObjectExpression") {
5339
+ return makeLeftHandSideExpression(exp);
5340
+ }
5333
5341
  return exp;
5334
5342
  });
5335
5343
  var FatArrowBody$1 = NoCommaBracedOrEmptyBlock;
@@ -5801,12 +5809,15 @@ ${input.slice(result.pos)}
5801
5809
  return $EVENT_C(ctx, state, "CallExpression", CallExpression$$);
5802
5810
  }
5803
5811
  var CallExpressionRest$0 = MemberExpressionRest;
5804
- var CallExpressionRest$1 = $TS($S($EXPECT($R4, "CallExpressionRest /(?=['\"`])/"), $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2) {
5805
- var literal = $2;
5812
+ var CallExpressionRest$1 = $TS($S($EXPECT($R4, "CallExpressionRest /(?=['\"`<])/"), $E(TypeArguments), $C(TemplateLiteral, StringLiteral)), function($skip, $loc, $0, $1, $2, $3) {
5813
+ var args = $2;
5814
+ var literal = $3;
5806
5815
  if (literal.type === "StringLiteral") {
5807
- return "`" + literal.token.slice(1, -1).replace(/(`|\$\{)/g, "\\$1") + "`";
5816
+ literal = "`" + literal.token.slice(1, -1).replace(/(`|\$\{)/g, "\\$1") + "`";
5808
5817
  }
5809
- return literal;
5818
+ if (!args)
5819
+ return literal;
5820
+ return [args, literal];
5810
5821
  });
5811
5822
  var CallExpressionRest$2 = $TS($S($E(OptionalShorthand), ArgumentsWithTrailingMemberExpressions), function($skip, $loc, $0, $1, $2) {
5812
5823
  if (!$1)
@@ -6146,15 +6157,55 @@ ${input.slice(result.pos)}
6146
6157
  function ArrowParameters(ctx, state) {
6147
6158
  return $EVENT_C(ctx, state, "ArrowParameters", ArrowParameters$$);
6148
6159
  }
6149
- var NonEmptyParameters$0 = $TS($S($E(TypeParameters), OpenParen, $E(ThisType), $Q(ParameterElement), $E(FunctionRestParameter), $Q(ParameterElement), $S(__, CloseParen)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
6160
+ var NonEmptyParameters$0 = $TS($S($E(TypeParameters), OpenParen, ParameterList, $S(__, CloseParen)), function($skip, $loc, $0, $1, $2, $3, $4) {
6150
6161
  var tp = $1;
6151
6162
  var open = $2;
6152
- var tt = $3;
6153
- var pes = $4;
6154
- var rest = $5;
6155
- var after = $6;
6156
- var close = $7;
6157
- const names = pes.flatMap((p) => p.names);
6163
+ var params = $3;
6164
+ var close = $4;
6165
+ let tt, before = [], rest, after = [], errors = [];
6166
+ function append(p) {
6167
+ (rest ? after : before).push(p);
6168
+ }
6169
+ for (const param of params) {
6170
+ switch (param.type) {
6171
+ case "ThisType":
6172
+ if (tt) {
6173
+ append({
6174
+ type: "Error",
6175
+ message: "Only one typed this parameter is allowed"
6176
+ });
6177
+ append(param);
6178
+ } else {
6179
+ tt = insertTrimmingSpace(param, "");
6180
+ if (before.length || rest) {
6181
+ let delim = tt.children.at(-1);
6182
+ if (Array.isArray(delim))
6183
+ delim = delim.at(-1);
6184
+ if (delim?.token !== ",") {
6185
+ tt = {
6186
+ ...tt,
6187
+ children: [...tt.children, ", "]
6188
+ };
6189
+ }
6190
+ }
6191
+ }
6192
+ break;
6193
+ case "FunctionRestParameter":
6194
+ if (rest) {
6195
+ append({
6196
+ type: "Error",
6197
+ message: "Only one rest parameter is allowed"
6198
+ });
6199
+ append(param);
6200
+ } else {
6201
+ rest = param;
6202
+ }
6203
+ break;
6204
+ default:
6205
+ append(param);
6206
+ }
6207
+ }
6208
+ const names = before.flatMap((p) => p.names);
6158
6209
  if (rest) {
6159
6210
  const restIdentifier = rest.binding.ref || rest.binding;
6160
6211
  names.push(...rest.names || []);
@@ -6171,7 +6222,7 @@ ${input.slice(result.pos)}
6171
6222
  tp,
6172
6223
  open,
6173
6224
  tt,
6174
- ...pes,
6225
+ ...before,
6175
6226
  // Remove delimiter
6176
6227
  { ...rest, children: rest.children.slice(0, -1) },
6177
6228
  close
@@ -6183,19 +6234,61 @@ ${input.slice(result.pos)}
6183
6234
  }
6184
6235
  return {
6185
6236
  type: "Parameters",
6186
- children: [tp, open, tt, ...pes, close],
6187
- names: pes.flatMap((p) => p.names),
6237
+ children: [tp, open, tt, ...before, close],
6238
+ names,
6188
6239
  tp
6189
6240
  };
6190
6241
  });
6191
6242
  function NonEmptyParameters(ctx, state) {
6192
6243
  return $EVENT(ctx, state, "NonEmptyParameters", NonEmptyParameters$0);
6193
6244
  }
6194
- var FunctionRestParameter$0 = $TS($S(__, BindingRestElement, $E(TypeSuffix), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4) {
6245
+ var ParameterList$0 = $TS($S($Q(Parameter), NestedParameterList), function($skip, $loc, $0, $1, $2) {
6246
+ return [...$1, ...$2];
6247
+ });
6248
+ var ParameterList$1 = $TV($Q($S(__, Parameter)), function($skip, $loc, $0, $1) {
6249
+ return $1.map(([eos, p]) => ({
6250
+ ...p,
6251
+ children: [eos, ...p.children]
6252
+ }));
6253
+ });
6254
+ var ParameterList$$ = [ParameterList$0, ParameterList$1];
6255
+ function ParameterList(ctx, state) {
6256
+ return $EVENT_C(ctx, state, "ParameterList", ParameterList$$);
6257
+ }
6258
+ var NestedParameterList$0 = $TS($S(PushIndent, $Q(NestedParameter), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
6259
+ var params = $2;
6260
+ if (!params.length)
6261
+ return $skip;
6262
+ return params;
6263
+ });
6264
+ function NestedParameterList(ctx, state) {
6265
+ return $EVENT(ctx, state, "NestedParameterList", NestedParameterList$0);
6266
+ }
6267
+ var NestedParameter$0 = $TS($S(Nested, $P(Parameter)), function($skip, $loc, $0, $1, $2) {
6268
+ var ws = $1;
6269
+ var params = $2;
6270
+ params = [...params];
6271
+ params[0] = {
6272
+ ...params[0],
6273
+ children: [ws, ...params[0].children]
6274
+ };
6275
+ return params;
6276
+ });
6277
+ function NestedParameter(ctx, state) {
6278
+ return $EVENT(ctx, state, "NestedParameter", NestedParameter$0);
6279
+ }
6280
+ var Parameter$0 = ThisType;
6281
+ var Parameter$1 = ParameterElement;
6282
+ var Parameter$2 = FunctionRestParameter;
6283
+ var Parameter$$ = [Parameter$0, Parameter$1, Parameter$2];
6284
+ function Parameter(ctx, state) {
6285
+ return $EVENT_C(ctx, state, "Parameter", Parameter$$);
6286
+ }
6287
+ var FunctionRestParameter$0 = $TS($S($N(EOS), BindingRestElement, $E(TypeSuffix), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4) {
6195
6288
  var id = $2;
6196
6289
  return {
6197
6290
  type: "FunctionRestParameter",
6198
- children: $0,
6291
+ children: $0.slice(1),
6199
6292
  names: id.names,
6200
6293
  binding: id.binding
6201
6294
  };
@@ -6203,12 +6296,14 @@ ${input.slice(result.pos)}
6203
6296
  function FunctionRestParameter(ctx, state) {
6204
6297
  return $EVENT(ctx, state, "FunctionRestParameter", FunctionRestParameter$0);
6205
6298
  }
6206
- var ParameterElement$0 = $TS($S(__, $E(AccessModifier), $C(BindingIdentifier, BindingPattern), $E(TypeSuffix), $E(Initializer), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
6299
+ var ParameterElement$0 = $TS($S($E(_), $E(AccessModifier), $E(_), $C(NWBindingIdentifier, BindingPattern), $E(TypeSuffix), $E(Initializer), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
6300
+ var accessModifier = $2;
6301
+ var binding = $4;
6207
6302
  return {
6208
6303
  type: "Parameter",
6209
6304
  children: $0,
6210
- names: $3.names,
6211
- accessModifier: $2
6305
+ names: binding.names,
6306
+ accessModifier
6212
6307
  };
6213
6308
  });
6214
6309
  function ParameterElement(ctx, state) {
@@ -6603,8 +6698,8 @@ ${input.slice(result.pos)}
6603
6698
  async,
6604
6699
  generator,
6605
6700
  modifier: {
6606
- async: !async.length,
6607
- generator: !generator.length
6701
+ async: !!async.length,
6702
+ generator: !!generator.length
6608
6703
  },
6609
6704
  block: null,
6610
6705
  children: !parameters.implicit ? [async, func, generator, wid, w, parameters, suffix] : [async, func, generator, wid, parameters, w, suffix]
@@ -6627,9 +6722,11 @@ ${input.slice(result.pos)}
6627
6722
  }
6628
6723
  if (hasAwait(block) && !signature.async.length) {
6629
6724
  signature.async.push("async ");
6725
+ signature.modifier.async = true;
6630
6726
  }
6631
6727
  if (hasYield(block) && !signature.generator.length) {
6632
6728
  signature.generator.push("*");
6729
+ signature.modifier.generator = true;
6633
6730
  }
6634
6731
  return {
6635
6732
  ...signature,
@@ -6804,10 +6901,11 @@ ${input.slice(result.pos)}
6804
6901
  function AmpersandBlockRHS(ctx, state) {
6805
6902
  return $EVENT(ctx, state, "AmpersandBlockRHS", AmpersandBlockRHS$0);
6806
6903
  }
6807
- var AmpersandBlockRHSBody$0 = $TS($S($E($S($N(_), $P(CallExpressionRest))), $E(QuestionMark), $E($S($N($EXPECT($R8, "AmpersandBlockRHSBody /[&]/")), $P(BinaryOpRHS)))), function($skip, $loc, $0, $1, $2, $3) {
6904
+ var AmpersandBlockRHSBody$0 = $TS($S($E($S($N(_), $P(CallExpressionRest))), $E(QuestionMark), $E($S(WAssignmentOp, $Q($S(NotDedented, UpdateExpression, WAssignmentOp)), NonPipelineExtendedExpression)), $E($S($N($EXPECT($R8, "AmpersandBlockRHSBody /[&]/")), $P(BinaryOpRHS)))), function($skip, $loc, $0, $1, $2, $3, $4) {
6808
6905
  var callExpRest = $1;
6809
6906
  var unaryPostfix = $2;
6810
- var binopRHS = $3;
6907
+ var assign = $3;
6908
+ var binopRHS = $4;
6811
6909
  if (!callExpRest && !binopRHS && !unaryPostfix)
6812
6910
  return $skip;
6813
6911
  const ref = makeRef("$");
@@ -6823,8 +6921,24 @@ ${input.slice(result.pos)}
6823
6921
  if (unaryPostfix) {
6824
6922
  exp = processUnaryExpression([], exp, unaryPostfix);
6825
6923
  }
6924
+ if (assign) {
6925
+ const [op1, more, rhs] = assign;
6926
+ const lhs = [
6927
+ [void 0, exp, ...op1],
6928
+ ...more.map((x) => [x[0], x[1], ...x[2]])
6929
+ ];
6930
+ exp = {
6931
+ type: "AssignmentExpression",
6932
+ children: [lhs, rhs],
6933
+ names: null,
6934
+ lhs,
6935
+ assigned: exp,
6936
+ exp: rhs,
6937
+ ref
6938
+ };
6939
+ }
6826
6940
  if (binopRHS) {
6827
- return {
6941
+ exp = {
6828
6942
  children: processBinaryOpExpression([exp, binopRHS[1]]),
6829
6943
  ref
6830
6944
  };
@@ -10709,6 +10823,12 @@ ${input.slice(result.pos)}
10709
10823
  function Class(ctx, state) {
10710
10824
  return $EVENT(ctx, state, "Class", Class$0);
10711
10825
  }
10826
+ var CloseAngleBracket$0 = $TV($EXPECT($L33, 'CloseAngleBracket ">"'), function($skip, $loc, $0, $1) {
10827
+ return { $loc, token: $1 };
10828
+ });
10829
+ function CloseAngleBracket(ctx, state) {
10830
+ return $EVENT(ctx, state, "CloseAngleBracket", CloseAngleBracket$0);
10831
+ }
10712
10832
  var CloseBrace$0 = $TV($EXPECT($L25, 'CloseBrace "}"'), function($skip, $loc, $0, $1) {
10713
10833
  return { $loc, token: $1 };
10714
10834
  });
@@ -12507,9 +12627,14 @@ ${input.slice(result.pos)}
12507
12627
  function TypeArrowFunction(ctx, state) {
12508
12628
  return $EVENT(ctx, state, "TypeArrowFunction", TypeArrowFunction$0);
12509
12629
  }
12510
- var TypeArguments$0 = $TS($S($EXPECT($L154, 'TypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L33, 'TypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
12630
+ var TypeArguments$0 = $TS($S(OpenAngleBracket, $P(TypeArgument), __, CloseAngleBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
12511
12631
  var args = $2;
12512
- return { ts: true, types: args.map(([, t]) => t), children: $0 };
12632
+ return {
12633
+ type: "TypeArguments",
12634
+ ts: true,
12635
+ types: args.map(([, t]) => t),
12636
+ children: $0
12637
+ };
12513
12638
  });
12514
12639
  function TypeArguments(ctx, state) {
12515
12640
  return $EVENT(ctx, state, "TypeArguments", TypeArguments$0);
@@ -12522,7 +12647,7 @@ ${input.slice(result.pos)}
12522
12647
  function TypeArgumentDelimiter(ctx, state) {
12523
12648
  return $EVENT(ctx, state, "TypeArgumentDelimiter", TypeArgumentDelimiter$0);
12524
12649
  }
12525
- var TypeParameters$0 = $TS($S($E(_), $EXPECT($L154, 'TypeParameters "<"'), $P(TypeParameter), __, $EXPECT($L33, 'TypeParameters ">"')), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
12650
+ var TypeParameters$0 = $TS($S($E(_), OpenAngleBracket, $P(TypeParameter), __, CloseAngleBracket), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
12526
12651
  var parameters = $3;
12527
12652
  return {
12528
12653
  type: "TypeParameters",
@@ -12555,7 +12680,7 @@ ${input.slice(result.pos)}
12555
12680
  function TypeParameterDelimiter(ctx, state) {
12556
12681
  return $EVENT_C(ctx, state, "TypeParameterDelimiter", TypeParameterDelimiter$$);
12557
12682
  }
12558
- var ThisType$0 = $T($S($C(This, AtThis), Colon, Type, ParameterElementDelimiter), function(value) {
12683
+ var ThisType$0 = $T($S($E(_), $C(This, AtThis), Colon, Type, ParameterElementDelimiter), function(value) {
12559
12684
  return { "type": "ThisType", "ts": true, "children": value };
12560
12685
  });
12561
12686
  function ThisType(ctx, state) {
@@ -12998,19 +13123,45 @@ ${input.slice(result.pos)}
12998
13123
  };
12999
13124
  module.prelude.push(["", [preludeVar, moduloRef, typeSuffix, " = (a, b) => (a % b + b) % b;", "\n"]]);
13000
13125
  },
13126
+ Falsy(FalsyRef) {
13127
+ module.prelude.push(["", [{
13128
+ ts: true,
13129
+ children: ["type ", FalsyRef, " = false | 0 | '' | 0n | null | undefined;", "\n"]
13130
+ }]]);
13131
+ },
13001
13132
  xor(xorRef) {
13133
+ const Falsy = module.getRef("Falsy");
13002
13134
  const typeSuffix = {
13003
13135
  ts: true,
13004
- children: [": (a: unknown, b: unknown) => boolean"]
13136
+ children: [
13137
+ ": <A, B>(a: A, b: B) => A extends ",
13138
+ Falsy,
13139
+ " ? B : B extends ",
13140
+ Falsy,
13141
+ " ? A : (false | (A & ",
13142
+ Falsy,
13143
+ " extends never ? never : B) | (B & ",
13144
+ Falsy,
13145
+ " extends never ? never : A))"
13146
+ ]
13005
13147
  };
13006
- module.prelude.push(["", [preludeVar, xorRef, typeSuffix, " = (a, b) => a ? !b && a : b;", "\n"]]);
13148
+ module.prelude.push(["", [preludeVar, xorRef, typeSuffix, " = (a, b) => (a ? !b && a : b)", asAny, ";", "\n"]]);
13007
13149
  },
13008
13150
  xnor(xnorRef) {
13151
+ const Falsy = module.getRef("Falsy");
13009
13152
  const typeSuffix = {
13010
13153
  ts: true,
13011
- children: [": (a: unknown, b: unknown) => boolean"]
13154
+ children: [
13155
+ ": <A, B>(a: A, b: B) => A & ",
13156
+ Falsy,
13157
+ " extends never ? B : (true | (B extends ",
13158
+ Falsy,
13159
+ " ? never : A) | (A extends ",
13160
+ Falsy,
13161
+ " ? never : B))"
13162
+ ]
13012
13163
  };
13013
- module.prelude.push(["", [preludeVar, xnorRef, typeSuffix, " = (a, b) => a ? b : !b || a;", "\n"]]);
13164
+ module.prelude.push(["", [preludeVar, xnorRef, typeSuffix, " = (a, b) => (a ? b : !b || a)", asAny, ";", "\n"]]);
13014
13165
  },
13015
13166
  returnSymbol(ref) {
13016
13167
  module.prelude.push({
@@ -13350,6 +13501,10 @@ ${input.slice(result.pos)}
13350
13501
  exports.ShortArrowParameters = ShortArrowParameters;
13351
13502
  exports.ArrowParameters = ArrowParameters;
13352
13503
  exports.NonEmptyParameters = NonEmptyParameters;
13504
+ exports.ParameterList = ParameterList;
13505
+ exports.NestedParameterList = NestedParameterList;
13506
+ exports.NestedParameter = NestedParameter;
13507
+ exports.Parameter = Parameter;
13353
13508
  exports.FunctionRestParameter = FunctionRestParameter;
13354
13509
  exports.ParameterElement = ParameterElement;
13355
13510
  exports.ParameterElementDelimiter = ParameterElementDelimiter;
@@ -13676,6 +13831,7 @@ ${input.slice(result.pos)}
13676
13831
  exports.Case = Case;
13677
13832
  exports.Catch = Catch;
13678
13833
  exports.Class = Class;
13834
+ exports.CloseAngleBracket = CloseAngleBracket;
13679
13835
  exports.CloseBrace = CloseBrace;
13680
13836
  exports.CloseBracket = CloseBracket;
13681
13837
  exports.CloseParen = CloseParen;
package/dist/esbuild.js CHANGED
@@ -42,14 +42,46 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var import_typescript = __toESM(require("typescript"));
44
44
  var tsvfs = __toESM(require("@typescript/vfs"));
45
+ var import_os = __toESM(require("os"));
45
46
  var formatHost = {
46
47
  getCurrentDirectory: () => import_typescript.default.sys.getCurrentDirectory(),
47
48
  getNewLine: () => import_typescript.default.sys.newLine,
48
49
  getCanonicalFileName: import_typescript.default.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
49
50
  };
50
51
  var isCivet = (id) => /\.civet$/.test(id);
51
- var isCivetTranspiled = (id) => /\.civet\.(m?)(j|t)s(x?)(\?transform)?$/.test(id);
52
- var isCivetTranspiledTS = (id) => /\.civet\.(m?)ts(x?)$/.test(id);
52
+ var isCivetTranspiled = (id) => /\.civet\.[jt]sx(\?transform)?$/.test(id);
53
+ var isCivetTranspiledTS = (id) => /\.civet\.tsx$/.test(id);
54
+ var postfixRE = /(\.[jt]sx)?[?#].*$/s;
55
+ var isWindows = import_os.default.platform() === "win32";
56
+ var windowsSlashRE = /\\/g;
57
+ function cleanCivetId(id) {
58
+ return id.replace(postfixRE, "");
59
+ }
60
+ function tryStatSync(file) {
61
+ try {
62
+ return fs.statSync(file, { throwIfNoEntry: false });
63
+ } catch {
64
+ return void 0;
65
+ }
66
+ }
67
+ function slash(p) {
68
+ return p.replace(windowsSlashRE, "/");
69
+ }
70
+ function normalizePath(id) {
71
+ return import_path.default.posix.normalize(isWindows ? slash(id) : id);
72
+ }
73
+ function tryFsResolve(file) {
74
+ const fileStat = tryStatSync(file);
75
+ if (fileStat?.isFile())
76
+ return normalizePath(file);
77
+ return void 0;
78
+ }
79
+ function resolveAbsolutePath(rootDir, id) {
80
+ const resolved = tryFsResolve(import_path.default.join(rootDir, id));
81
+ if (!resolved)
82
+ return tryFsResolve(id);
83
+ return resolved;
84
+ }
53
85
  var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
54
86
  if (options.dts && options.js) {
55
87
  throw new Error("Can't have both `dts` and `js` be set to `true`.");
@@ -62,7 +94,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
62
94
  let fsMap = /* @__PURE__ */ new Map();
63
95
  const sourceMaps = /* @__PURE__ */ new Map();
64
96
  let compilerOptions;
65
- let rootDir;
97
+ let rootDir = process.cwd();
66
98
  return {
67
99
  name: "unplugin-civet",
68
100
  enforce: "pre",
@@ -162,10 +194,11 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
162
194
  return null;
163
195
  if (!isCivet(id) && !isCivetTranspiled(id))
164
196
  return null;
165
- const absolutePath = rootDir != null && import_path.default.isAbsolute(id) ? import_path.default.join(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
197
+ id = cleanCivetId(id);
198
+ const absolutePath = import_path.default.isAbsolute(id) ? resolveAbsolutePath(rootDir, id) : import_path.default.resolve(import_path.default.dirname(importer ?? ""), id);
199
+ if (!absolutePath)
200
+ return null;
166
201
  const relativeId = import_path.default.relative(process.cwd(), absolutePath);
167
- if (isCivetTranspiled(id))
168
- return relativeId.replace(/\?transform$/, "");
169
202
  const relativePath = relativeId + outExt;
170
203
  return relativePath;
171
204
  },
@@ -206,9 +239,9 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
206
239
  if (options.dts || options.typecheck) {
207
240
  const resolved = import_path.default.resolve(process.cwd(), id);
208
241
  fsMap.set(resolved, code);
209
- const slash = resolved.replace(/\\/g, "/");
210
- if (resolved !== slash)
211
- fsMap.set(slash, code);
242
+ const slashed = slash(resolved);
243
+ if (resolved !== slashed)
244
+ fsMap.set(slashed, code);
212
245
  }
213
246
  return null;
214
247
  },