hermes-parser
Advanced tools
Comparing version 0.4.8 to 0.5.0
@@ -1,11 +0,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _visitorKeys = require("./generated/visitor-keys"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -17,6 +16,4 @@ | ||
var _require = require('./HermesParserVisitorKeys'), | ||
HERMES_AST_VISITOR_KEYS = _require.HERMES_AST_VISITOR_KEYS, | ||
NODE_CHILD = _require.NODE_CHILD, | ||
NODE_LIST_CHILD = _require.NODE_LIST_CHILD; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/** | ||
@@ -26,8 +23,10 @@ * The base class for transforming the Hermes AST to the desired output format. | ||
*/ | ||
var HermesASTAdapter = /*#__PURE__*/function () { | ||
function HermesASTAdapter(options, code) { | ||
function HermesASTAdapter(options) { | ||
_classCallCheck(this, HermesASTAdapter); | ||
_defineProperty(this, "sourceFilename", void 0); | ||
_defineProperty(this, "sourceType", void 0); | ||
this.sourceFilename = options.sourceFilename; | ||
@@ -76,5 +75,4 @@ this.sourceType = options.sourceType; | ||
key: "mapNode", | ||
value: function mapNode(node) { | ||
this.fixSourceLocation(node); | ||
return this.mapNodeDefault(node); | ||
value: function mapNode(_node) { | ||
throw new Error('Implemented in subclasses'); | ||
} | ||
@@ -84,3 +82,3 @@ }, { | ||
value: function mapNodeDefault(node) { | ||
var visitorKeys = HERMES_AST_VISITOR_KEYS[node.type]; | ||
var visitorKeys = _visitorKeys.HERMES_AST_VISITOR_KEYS[node.type]; | ||
@@ -90,3 +88,3 @@ for (var key in visitorKeys) { | ||
if (childType === NODE_CHILD) { | ||
if (childType === _visitorKeys.NODE_CHILD) { | ||
var child = node[key]; | ||
@@ -97,3 +95,3 @@ | ||
} | ||
} else if (childType === NODE_LIST_CHILD) { | ||
} else if (childType === _visitorKeys.NODE_LIST_CHILD) { | ||
var children = node[key]; | ||
@@ -120,3 +118,3 @@ | ||
key: "fixSourceLocation", | ||
value: function fixSourceLocation(node) { | ||
value: function fixSourceLocation(_node) { | ||
throw new Error('Implemented in subclasses'); | ||
@@ -145,3 +143,4 @@ } | ||
key: "mapEmpty", | ||
value: function mapEmpty(node) { | ||
value: function mapEmpty(_node) { | ||
// $FlowExpectedError | ||
return null; | ||
@@ -206,2 +205,2 @@ } | ||
module.exports = HermesASTAdapter; | ||
exports["default"] = HermesASTAdapter; |
@@ -7,2 +7,3 @@ /** | ||
* | ||
* | ||
* @format | ||
@@ -12,18 +13,34 @@ */ | ||
var HermesParserDeserializer = require('./HermesParserDeserializer'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.parse = parse; | ||
var HermesParserWASM = require('./HermesParserWASM'); | ||
var _HermesParserDeserializer = _interopRequireDefault(require("./HermesParserDeserializer")); | ||
var hermesParse = HermesParserWASM.cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number']); | ||
var hermesParseResult_free = HermesParserWASM.cwrap('hermesParseResult_free', 'void', ['number']); | ||
var hermesParseResult_getError = HermesParserWASM.cwrap('hermesParseResult_getError', 'string', ['number']); | ||
var hermesParseResult_getErrorLine = HermesParserWASM.cwrap('hermesParseResult_getErrorLine', 'number', ['number']); | ||
var hermesParseResult_getErrorColumn = HermesParserWASM.cwrap('hermesParseResult_getErrorColumn', 'number', ['number']); | ||
var hermesParseResult_getProgramBuffer = HermesParserWASM.cwrap('hermesParseResult_getProgramBuffer', 'number', ['number']); | ||
var hermesParseResult_getPositionBuffer = HermesParserWASM.cwrap('hermesParseResult_getPositionBuffer', 'number', ['number']); | ||
var hermesParseResult_getPositionBufferSize = HermesParserWASM.cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']); // Copy a string into the WASM heap and null-terminate | ||
var _HermesParserWASM = _interopRequireDefault(require("./HermesParserWASM")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var hermesParse = _HermesParserWASM["default"].cwrap('hermesParse', 'number', ['number', 'number', 'number', 'number', 'number']); | ||
var hermesParseResult_free = _HermesParserWASM["default"].cwrap('hermesParseResult_free', 'void', ['number']); | ||
var hermesParseResult_getError = _HermesParserWASM["default"].cwrap('hermesParseResult_getError', 'string', ['number']); | ||
var hermesParseResult_getErrorLine = _HermesParserWASM["default"].cwrap('hermesParseResult_getErrorLine', 'number', ['number']); | ||
var hermesParseResult_getErrorColumn = _HermesParserWASM["default"].cwrap('hermesParseResult_getErrorColumn', 'number', ['number']); | ||
var hermesParseResult_getProgramBuffer = _HermesParserWASM["default"].cwrap('hermesParseResult_getProgramBuffer', 'number', ['number']); | ||
var hermesParseResult_getPositionBuffer = _HermesParserWASM["default"].cwrap('hermesParseResult_getPositionBuffer', 'number', ['number']); | ||
var hermesParseResult_getPositionBufferSize = _HermesParserWASM["default"].cwrap('hermesParseResult_getPositionBufferSize', 'number', ['number']); // Copy a string into the WASM heap and null-terminate | ||
function copyToHeap(buffer, addr) { | ||
HermesParserWASM.HEAP8.set(buffer, addr); | ||
HermesParserWASM.HEAP8[addr + buffer.length] = 0; | ||
_HermesParserWASM["default"].HEAP8.set(buffer, addr); | ||
_HermesParserWASM["default"].HEAP8[addr + buffer.length] = 0; | ||
} | ||
@@ -35,3 +52,3 @@ | ||
var sourceAddr = HermesParserWASM._malloc(sourceBuffer.length + 1); | ||
var sourceAddr = _HermesParserWASM["default"]._malloc(sourceBuffer.length + 1); | ||
@@ -52,3 +69,4 @@ if (!sourceAddr) { | ||
if (err) { | ||
var syntaxError = new SyntaxError(err); | ||
var syntaxError = new SyntaxError(err); // $FlowExpectedError[prop-missing] | ||
syntaxError.loc = { | ||
@@ -61,3 +79,3 @@ line: hermesParseResult_getErrorLine(parseResult), | ||
var deserializer = new HermesParserDeserializer(hermesParseResult_getProgramBuffer(parseResult), hermesParseResult_getPositionBuffer(parseResult), hermesParseResult_getPositionBufferSize(parseResult), HermesParserWASM, options); | ||
var deserializer = new _HermesParserDeserializer["default"](hermesParseResult_getProgramBuffer(parseResult), hermesParseResult_getPositionBuffer(parseResult), hermesParseResult_getPositionBufferSize(parseResult), _HermesParserWASM["default"], options); | ||
return deserializer.deserialize(); | ||
@@ -68,8 +86,4 @@ } finally { | ||
} finally { | ||
HermesParserWASM._free(sourceAddr); | ||
_HermesParserWASM["default"]._free(sourceAddr); | ||
} | ||
} | ||
module.exports = { | ||
parse: parse | ||
}; | ||
} |
@@ -7,2 +7,3 @@ /** | ||
* | ||
* | ||
* @format | ||
@@ -20,3 +21,9 @@ */ | ||
function HermesParserDecodeUTF8String(ptr, length, heap) { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = HermesParserDecodeUTF8String; | ||
function HermesParserDecodeUTF8String(ptrIn, length, heap) { | ||
var ptr = ptrIn; | ||
var endPtr = ptr + length; | ||
@@ -63,4 +70,2 @@ var str = ''; | ||
return str; | ||
} | ||
module.exports = HermesParserDecodeUTF8String; | ||
} |
@@ -7,2 +7,3 @@ /** | ||
* | ||
* | ||
* @format | ||
@@ -12,2 +13,13 @@ */ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _HermesParserDecodeUTF8String = _interopRequireDefault(require("./HermesParserDecodeUTF8String")); | ||
var _HermesParserNodeDeserializers = _interopRequireDefault(require("./HermesParserNodeDeserializers")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -21,10 +33,24 @@ | ||
var HermesParserDecodeUTF8String = require('./HermesParserDecodeUTF8String'); | ||
var NODE_DESERIALIZERS = require('./HermesParserNodeDeserializers'); | ||
var HermesParserDeserializer = /*#__PURE__*/function () { | ||
// Matches StoredComment::Kind enum in JSLexer.h | ||
// Matches TokenType enum in HermesParserJSSerializer.h | ||
function HermesParserDeserializer(programBuffer, positionBuffer, positionBufferSize, wasmParser, options) { | ||
_classCallCheck(this, HermesParserDeserializer); | ||
_defineProperty(this, "programBufferIdx", void 0); | ||
_defineProperty(this, "positionBufferIdx", void 0); | ||
_defineProperty(this, "positionBufferSize", void 0); | ||
_defineProperty(this, "locMap", void 0); | ||
_defineProperty(this, "HEAPU8", void 0); | ||
_defineProperty(this, "HEAPU32", void 0); | ||
_defineProperty(this, "HEAPF64", void 0); | ||
_defineProperty(this, "options", void 0); | ||
_defineProperty(this, "commentTypes", ['CommentLine', 'CommentBlock', 'InterpreterDirective']); | ||
@@ -66,3 +92,3 @@ | ||
if (this.options.tokens) { | ||
if (this.options.tokens === true) { | ||
program.tokens = this.deserializeTokens(); | ||
@@ -120,3 +146,3 @@ } | ||
var size = this.next(); | ||
return HermesParserDecodeUTF8String(ptr, size, this.HEAPU8); | ||
return (0, _HermesParserDecodeUTF8String["default"])(ptr, size, this.HEAPU8); | ||
} | ||
@@ -140,3 +166,4 @@ /** | ||
var nodeDeserializer = NODE_DESERIALIZERS[nodeType - 1].bind(this); | ||
var nodeDeserializer = _HermesParserNodeDeserializers["default"][nodeType - 1].bind(this); | ||
return nodeDeserializer(); | ||
@@ -160,7 +187,3 @@ } | ||
return nodeList; | ||
} // Matches StoredComment::Kind enum in JSLexer.h | ||
}, { | ||
key: "deserializeComments", | ||
} | ||
/** | ||
@@ -171,2 +194,5 @@ * Comments are serialized as a node list, where each comment is serialized | ||
*/ | ||
}, { | ||
key: "deserializeComments", | ||
value: function deserializeComments() { | ||
@@ -217,2 +243,3 @@ var size = this.next(); | ||
value: function addEmptyLoc() { | ||
// $FlowExpectedError | ||
var loc = {}; | ||
@@ -259,2 +286,2 @@ this.locMap[this.next()] = loc; | ||
module.exports = HermesParserDeserializer; | ||
exports["default"] = HermesParserDeserializer; |
@@ -7,2 +7,3 @@ /** | ||
* | ||
* | ||
* @format | ||
@@ -707,3 +708,3 @@ */ | ||
source: this.deserializeNode(), | ||
attributes: this.deserializeNodeList(), | ||
assertions: this.deserializeNodeList(), | ||
importKind: this.deserializeString() | ||
@@ -710,0 +711,0 @@ }; |
@@ -1,15 +0,18 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
'use strict'; | ||
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _HermesASTAdapter2 = _interopRequireDefault(require("./HermesASTAdapter")); | ||
var _excluded = ["comments"]; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
@@ -35,12 +38,10 @@ | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var HermesASTAdapter = require('./HermesASTAdapter'); | ||
var HermesToBabelAdapter = /*#__PURE__*/function (_HermesASTAdapter) { | ||
@@ -152,3 +153,3 @@ _inherits(HermesToBabelAdapter, _HermesASTAdapter); | ||
comments = _this$mapNodeWithDire.comments, | ||
program = _objectWithoutProperties(_this$mapNodeWithDire, ["comments"]); | ||
program = _objectWithoutProperties(_this$mapNodeWithDire, _excluded); | ||
@@ -445,4 +446,4 @@ program.sourceType = this.getSourceType(); // Adjust start loc to beginning of file | ||
return HermesToBabelAdapter; | ||
}(HermesASTAdapter); | ||
}(_HermesASTAdapter2["default"]); | ||
module.exports = HermesToBabelAdapter; | ||
exports["default"] = HermesToBabelAdapter; |
@@ -1,13 +0,14 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
'use strict'; | ||
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _HermesASTAdapter2 = _interopRequireDefault(require("./HermesASTAdapter")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -25,11 +26,11 @@ | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var HermesASTAdapter = require('./HermesASTAdapter'); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -47,2 +48,5 @@ var HermesToESTreeAdapter = /*#__PURE__*/function (_HermesASTAdapter) { | ||
_this = _super.call(this, options); | ||
_defineProperty(_assertThisInitialized(_this), "code", void 0); | ||
_this.code = code; | ||
@@ -212,4 +216,4 @@ return _this; | ||
return HermesToESTreeAdapter; | ||
}(HermesASTAdapter); | ||
}(_HermesASTAdapter2["default"]); | ||
module.exports = HermesToESTreeAdapter; | ||
exports["default"] = HermesToESTreeAdapter; |
@@ -12,13 +12,38 @@ /** | ||
var HermesParser = require('./HermesParser'); | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var HermesToBabelAdapter = require('./HermesToBabelAdapter'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.parse = parse; | ||
var HermesToESTreeAdapter = require('./HermesToESTreeAdapter'); | ||
var HermesParser = _interopRequireWildcard(require("./HermesParser")); | ||
function getOptions(options) { | ||
var _HermesToBabelAdapter = _interopRequireDefault(require("./HermesToBabelAdapter")); | ||
var _HermesToESTreeAdapter = _interopRequireDefault(require("./HermesToESTreeAdapter")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var DEFAULTS = { | ||
flow: 'detect' | ||
}; | ||
function getOptions() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _objectSpread({}, DEFAULTS); | ||
// Default to detecting whether to parse Flow syntax by the presence | ||
// of an pragma. | ||
if (options.flow == null) { | ||
options.flow = 'detect'; | ||
options.flow = DEFAULTS.flow; | ||
} else if (options.flow != 'all' && options.flow != 'detect') { | ||
@@ -41,7 +66,8 @@ throw new Error('flow option must be "all" or "detect"'); | ||
function getAdapter(options, code) { | ||
return options.babel === true ? new HermesToBabelAdapter(options) : new HermesToESTreeAdapter(options, code); | ||
} | ||
return options.babel === true ? new _HermesToBabelAdapter["default"](options) : new _HermesToESTreeAdapter["default"](options, code); | ||
} // $FlowExpectedError[unclear-type] | ||
function parse(code) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// eslint-disable-next-line no-redeclare | ||
function parse(code, opts) { | ||
var options = getOptions(opts); | ||
@@ -51,6 +77,2 @@ var ast = HermesParser.parse(code, options); | ||
return adapter.transform(ast); | ||
} | ||
module.exports = { | ||
parse: parse | ||
}; | ||
} |
{ | ||
"name": "hermes-parser", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"description": "A JavaScript parser built from the Hermes engine", | ||
@@ -11,2 +11,5 @@ "main": "dist/index.js", | ||
}, | ||
"dependencies": { | ||
"hermes-estree": "0.5.0" | ||
}, | ||
"files": [ | ||
@@ -13,0 +16,0 @@ "dist" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1119641
25
1
3450
+ Addedhermes-estree@0.5.0
+ Addedhermes-estree@0.5.0(transitive)