astx
Version:
super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring
37 lines (29 loc) • 1.22 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = compileGenericTypeAnnotationMatcher;
var _types = require("../types");
var _Placeholder = _interopRequireDefault(require("./Placeholder"));
var _SpecialMatcher = _interopRequireDefault(require("./SpecialMatcher"));
function compileGenericTypeAnnotationMatcher(path, compileOptions) {
var _path$value = path.value,
id = _path$value.id,
typeParameters = _path$value.typeParameters;
var n = compileOptions.backend.t.namedTypes;
if (n.Identifier.check(id)) {
if (typeParameters == null) {
var placeholderMatcher = (0, _Placeholder["default"])(path, id.name, compileOptions, {
nodeType: 'FlowType'
});
if (placeholderMatcher) return placeholderMatcher;
} else {
var typeParametersPath = path.get('typeParameters');
if ((0, _types.pathIs)(typeParametersPath, n.TypeParameterInstantiation)) {
var special = (0, _SpecialMatcher["default"])(path, id.name, typeParametersPath.get('params'), compileOptions);
if (special) return special;
}
}
}
}