You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

type-annotations.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";;
  2. /**
  3. * Type annotation defs shared between Flow and TypeScript.
  4. * These defs could not be defined in ./flow.ts or ./typescript.ts directly
  5. * because they use the same name.
  6. */
  7. var __importDefault = (this && this.__importDefault) || function (mod) {
  8. return (mod && mod.__esModule) ? mod : { "default": mod };
  9. };
  10. Object.defineProperty(exports, "__esModule", { value: true });
  11. var types_1 = __importDefault(require("../lib/types"));
  12. var shared_1 = __importDefault(require("../lib/shared"));
  13. function default_1(fork) {
  14. var types = fork.use(types_1.default);
  15. var def = types.Type.def;
  16. var or = types.Type.or;
  17. var defaults = fork.use(shared_1.default).defaults;
  18. var TypeAnnotation = or(def("TypeAnnotation"), def("TSTypeAnnotation"), null);
  19. var TypeParamDecl = or(def("TypeParameterDeclaration"), def("TSTypeParameterDeclaration"), null);
  20. def("Identifier")
  21. .field("typeAnnotation", TypeAnnotation, defaults["null"]);
  22. def("ObjectPattern")
  23. .field("typeAnnotation", TypeAnnotation, defaults["null"]);
  24. def("Function")
  25. .field("returnType", TypeAnnotation, defaults["null"])
  26. .field("typeParameters", TypeParamDecl, defaults["null"]);
  27. def("ClassProperty")
  28. .build("key", "value", "typeAnnotation", "static")
  29. .field("value", or(def("Expression"), null))
  30. .field("static", Boolean, defaults["false"])
  31. .field("typeAnnotation", TypeAnnotation, defaults["null"]);
  32. ["ClassDeclaration",
  33. "ClassExpression",
  34. ].forEach(function (typeName) {
  35. def(typeName)
  36. .field("typeParameters", TypeParamDecl, defaults["null"])
  37. .field("superTypeParameters", or(def("TypeParameterInstantiation"), def("TSTypeParameterInstantiation"), null), defaults["null"])
  38. .field("implements", or([def("ClassImplements")], [def("TSExpressionWithTypeArguments")]), defaults.emptyArray);
  39. });
  40. }
  41. exports.default = default_1;
  42. module.exports = exports["default"];