@di-framework/tsc 6.0.4 → 6.0.6

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 (2) hide show
  1. package/package.json +1 -1
  2. package/plugin/main.go +18 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@di-framework/tsc",
3
- "version": "6.0.4",
3
+ "version": "6.0.6",
4
4
  "description": "ttsc transform that injects runtime parameter checks from TypeScript types (assertAll)",
5
5
  "author": "@di-framework Contributors",
6
6
  "license": "(MIT OR Apache-2.0)",
package/plugin/main.go CHANGED
@@ -20,6 +20,8 @@ import (
20
20
  "github.com/samchon/ttsc/packages/ttsc/driver"
21
21
  )
22
22
 
23
+ const expectedMessagePrefix = "Expected "
24
+
23
25
  type options struct {
24
26
  cwd string
25
27
  emit bool
@@ -449,13 +451,13 @@ func stmtsFromCheckerTypeSeen(
449
451
  if !ok {
450
452
  return nil
451
453
  }
452
- return []*shimast.Node{throwIf(factory, invalid, "Expected "+path+" to be a valid enum value")}
454
+ return []*shimast.Node{throwIf(factory, invalid, expectedMessagePrefix+path+" to be a valid enum value")}
453
455
  case classTypeSymbol(t) != nil:
454
456
  invalid, className, ok := classInvalidPredicate(factory, checker, enclosing, path, t)
455
457
  if !ok {
456
458
  return nil
457
459
  }
458
- return []*shimast.Node{throwIf(factory, invalid, "Expected "+path+" to be an instance of "+className)}
460
+ return []*shimast.Node{throwIf(factory, invalid, expectedMessagePrefix+path+" to be an instance of "+className)}
459
461
  case flags&shimchecker.TypeFlagsUnion != 0:
460
462
  members := t.Types()
461
463
  if len(members) == 0 || len(members) > 12 {
@@ -473,7 +475,7 @@ func stmtsFromCheckerTypeSeen(
473
475
  invalid = binary(factory, invalid, shimast.KindAmpersandAmpersandToken, memberInvalid)
474
476
  }
475
477
  }
476
- return []*shimast.Node{throwIf(factory, invalid, "Expected "+path+" to match its union type")}
478
+ return []*shimast.Node{throwIf(factory, invalid, expectedMessagePrefix+path+" to match its union type")}
477
479
  case flags&shimchecker.TypeFlagsIntersection != 0:
478
480
  if base, ok := brandedBaseType(checker, t); ok {
479
481
  return stmtsFromCheckerTypeSeen(factory, checker, enclosing, path, base, state, depth+1)
@@ -513,7 +515,7 @@ func stmtsFromCheckerTypeSeen(
513
515
  if !ok {
514
516
  return nil
515
517
  }
516
- return []*shimast.Node{throwIf(factory, invalid, "Expected "+path+" to match its template literal type")}
518
+ return []*shimast.Node{throwIf(factory, invalid, expectedMessagePrefix+path+" to match its template literal type")}
517
519
  case flags&shimchecker.TypeFlagsString != 0:
518
520
  return []*shimast.Node{typeofCheck(factory, path, "string")}
519
521
  case flags&shimchecker.TypeFlagsNumber != 0:
@@ -527,13 +529,13 @@ func stmtsFromCheckerTypeSeen(
527
529
  if !ok {
528
530
  return nil
529
531
  }
530
- return []*shimast.Node{throwIf(factory, invalid, "Expected "+path+" to be an array with valid elements")}
532
+ return []*shimast.Node{throwIf(factory, invalid, expectedMessagePrefix+path+" to be an array with valid elements")}
531
533
  case flags&shimchecker.TypeFlagsObject != 0 && shimchecker.IsTupleType(t):
532
534
  invalid, ok := tupleInvalidPredicate(factory, checker, enclosing, path, t, state, depth)
533
535
  if !ok {
534
536
  return nil
535
537
  }
536
- return []*shimast.Node{throwIf(factory, invalid, "Expected "+path+" to be a valid tuple")}
538
+ return []*shimast.Node{throwIf(factory, invalid, expectedMessagePrefix+path+" to be a valid tuple")}
537
539
  case flags&shimchecker.TypeFlagsObject != 0:
538
540
  return structuralStatements(factory, checker, enclosing, path, t, state, depth)
539
541
  default:
@@ -871,7 +873,7 @@ func structuralStatements(
871
873
  indexType, hasStringIndex, _ := stringIndexValueType(checker, t)
872
874
  if hasStringIndex {
873
875
  invalid, _ := stringIndexInvalidPredicate(factory, checker, enclosing, path, indexType, state, depth)
874
- out = append(out, throwIf(factory, invalid, "Expected "+path+" to have valid string-indexed values"))
876
+ out = append(out, throwIf(factory, invalid, expectedMessagePrefix+path+" to have valid string-indexed values"))
875
877
  }
876
878
  return out
877
879
  }
@@ -1239,11 +1241,11 @@ func arrayInvalidPredicate(
1239
1241
 
1240
1242
  func equalityCheck(factory *shimast.NodeFactory, path string, expected *shimast.Expression, label string) *shimast.Node {
1241
1243
  cond := binary(factory, pathExpr(factory, path), shimast.KindExclamationEqualsEqualsToken, expected)
1242
- return throwIf(factory, cond, "Expected "+path+" to equal "+label)
1244
+ return throwIf(factory, cond, expectedMessagePrefix+path+" to equal "+label)
1243
1245
  }
1244
1246
 
1245
1247
  func requiredPropertyCheck(factory *shimast.NodeFactory, path, property string) *shimast.Node {
1246
- return throwIf(factory, missingPropertyPredicate(factory, path, property), "Expected "+path+" to have required property "+strconv.Quote(property))
1248
+ return throwIf(factory, missingPropertyPredicate(factory, path, property), expectedMessagePrefix+path+" to have required property "+strconv.Quote(property))
1247
1249
  }
1248
1250
 
1249
1251
  func missingPropertyPredicate(factory *shimast.NodeFactory, path, property string) *shimast.Expression {
@@ -1319,16 +1321,16 @@ func pathExpr(factory *shimast.NodeFactory, path string) *shimast.Expression {
1319
1321
  end = quotedEnd + 2
1320
1322
  continue
1321
1323
  }
1322
- close := strings.IndexByte(path[start:], ']')
1323
- if close < 0 {
1324
+ bracketEnd := strings.IndexByte(path[start:], ']')
1325
+ if bracketEnd < 0 {
1324
1326
  return expr
1325
1327
  }
1326
- close += start
1327
- index := path[start:close]
1328
+ bracketEnd += start
1329
+ index := path[start:bracketEnd]
1328
1330
  // An identifier-shaped synthesized index prints as the numeric token while
1329
1331
  // avoiding the emitter asking source-text questions of a detached literal.
1330
1332
  expr = factory.NewElementAccessExpression(expr, nil, factory.NewIdentifier(index), 0)
1331
- end = close + 1
1333
+ end = bracketEnd + 1
1332
1334
  }
1333
1335
  return expr
1334
1336
  }
@@ -1340,7 +1342,7 @@ func typeofCheck(factory *shimast.NodeFactory, path, kind string) *shimast.Node
1340
1342
  shimast.KindExclamationEqualsEqualsToken,
1341
1343
  factory.NewStringLiteral(kind, shimast.TokenFlagsNone),
1342
1344
  )
1343
- return throwIf(factory, cond, "Expected "+path+" to be a "+kind)
1345
+ return throwIf(factory, cond, expectedMessagePrefix+path+" to be a "+kind)
1344
1346
  }
1345
1347
 
1346
1348
  func objectCheck(factory *shimast.NodeFactory, path string) *shimast.Node {
@@ -1357,7 +1359,7 @@ func objectCheck(factory *shimast.NodeFactory, path string) *shimast.Node {
1357
1359
  factory.NewToken(shimast.KindNullKeyword),
1358
1360
  )
1359
1361
  cond := binary(factory, notObject, shimast.KindBarBarToken, isNull)
1360
- return throwIf(factory, cond, "Expected "+path+" to be an object")
1362
+ return throwIf(factory, cond, expectedMessagePrefix+path+" to be an object")
1361
1363
  }
1362
1364
 
1363
1365
  func throwIf(factory *shimast.NodeFactory, condition *shimast.Expression, message string) *shimast.Node {