Created
December 28, 2017 23:08
-
-
Save cmstead/7e72bb3dc4db04ef562531bd04c8e78a to your computer and use it in GitHub Desktop.
Simplified type helper for JS Refactor example source types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const signet = require('signet')(); | |
(function () { | |
signet.defineDuckType('astPosition', { | |
line: 'leftBoundedInt<1>', | |
column: 'leftBoundedInt<0>' | |
}); | |
signet.defineDuckType('astCoords', { | |
start: 'astPosition', | |
end: 'astPosition' | |
}); | |
signet.alias('selectionCoords', 'astCoords'); | |
signet.defineDuckType('astNode', { | |
type: '?string', | |
loc: 'astCoords' | |
}); | |
signet.alias('nodeTypes', 'array<string>'); | |
signet.defineDuckType('traversalOptions', { | |
enter: '?function<astNode => undefined>', | |
leave: '?function<astNode => undefined>' | |
}); | |
})(); | |
function errorBuilder(validationResult, args, signatureTree, functionName) { | |
const defaultError = signet.buildInputErrorMessage(validationResult, args, signatureTree, functionName); | |
return defaultError + '\n\nJS Refactoring types are defined in the typeHelper file; more info can be found in type definitions.'; | |
} | |
function enforce(signature, fn) { | |
return signet.enforce(signature, fn, { | |
inputErrorBuilder: errorBuilder, | |
outputErrorBuilder: errorBuilder | |
}); | |
} | |
function typeHelper() { | |
return { | |
enforce: enforce, | |
isTypeOf: signet.isTypeOf | |
}; | |
} | |
module.exports = typeHelper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment