How to use the babylon/lib/parser.plugins function in babylon

To help you get started, we’ve selected a few babylon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eponymous-labs / babel-plugin-top-level-await / dist / top-level-await.js View on Github external
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


_parser.plugins.topLevelAwait = function (instance) {
    instance.extend("parseTopLevel", function (file, program) {
        return function (file, program) {
            program.sourceType = this.options.sourceType;

            // set state to inAsync to allow awaits
            this.state.inAsync = true;

            // allow strings at the top of a script
            // plus the only useful directive is "use strict"
            // which gets added by babel anyways

            var allowDirectives = false;
            this.parseBlockBody(program, allowDirectives, true, _types.types.eof);

            file.program = this.finishNode(program, "Program");
            file.comments = this.state.comments;
github nikaspran / coffee-to-ts / lib / babel / loadPlugins.js View on Github external
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

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 pluginsToLoad = (0, _lodash2.default)(_fs2.default.readdirSync(__dirname)).reject(function (plugin) {
	return plugin.startsWith('loadPlugins') || plugin.startsWith('common');
}).map(function (plugin) {
	return plugin.split('.').shift();
}).map(function (pluginName) {
	return _defineProperty({}, pluginName, require('./' + pluginName).parser);
}).reduce(_lodash2.default.assign);

Object.assign(_parser.plugins, pluginsToLoad);

function generatePlugins() {
	return [require.resolve('./loadPlugins')].concat(_toConsumableArray(_lodash2.default.keys(pluginsToLoad).map(function (plugin) {
		return require.resolve('./' + plugin);
	})));
}

function addParserPlugins() {
	return {
		manipulateOptions: function manipulateOptions(opts, parserOpts) {
			var _parserOpts$plugins;

			parserOpts.plugins.push('classProperties');
			(_parserOpts$plugins = parserOpts.plugins).push.apply(_parserOpts$plugins, _toConsumableArray(_lodash2.default.keys(pluginsToLoad)));
		}
	};