How to use acorn-dynamic-import - 10 common examples

To help you get started, we’ve selected a few acorn-dynamic-import 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 JC-Orozco / BlocksIDE / src / lib / js2blocks.js View on Github external
export function parseCode(code){
  let Blockly = window.Blockly;
  let workspace = Blockly.mainWorkspace;
  let ast1, xml1;
  let options;
  let comments = [];
  let block_loc = [];
  try{
    //console1.value = '';
    window._BIDE.b2c_error = false
    options = {
      sourceType: 'module',
      locations: true,
      onComment: comments
    };
    ast1 = acorn.parse(code, options);
    console.log(comments)
    xml1 = walk1(ast1, comments, block_loc);
    //console.log(xml1);
    workspace.clear();
    Blockly.Xml.domToWorkspace(workspace, xml1);
    workspace.cleanUp_(); // workspace.cleanUp(); // In updated Blockly 
    window._BIDE.updateWorkspace()
 //workspace.addChangeListener(window._BIDE.updateWorkspace);
    //var blockly_code = Blockly.JavaScript.workspaceToCode(Blockly.mainWorkspace);
    //console.log(blockly_code);  
  } catch(err){
    console.log(err)
    window._BIDE.b2c_error = true
    
    let tb = workspace.topBlocks_
    let id = tb[tb.length-1].id
github fossasia / susper.com / node_modules / webpack / lib / Parser.js View on Github external
let ast;
		const comments = [];
		for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
			if(!ast) {
				try {
					comments.length = 0;
					POSSIBLE_AST_OPTIONS[i].onComment = comments;
					ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
				} catch(e) {
					// ignore the error
				}
			}
		}
		if(!ast) {
			// for the error
			ast = acorn.parse(source, {
				ranges: true,
				locations: true,
				ecmaVersion: ECMA_VERSION,
				sourceType: "module",
				plugins: {
					dynamicImport: true
				},
				onComment: comments
			});
		}
		if(!ast || typeof ast !== "object")
			throw new Error("Source couldn't be parsed");
		const oldScope = this.scope;
		const oldState = this.state;
		const oldComments = this.comments;
		this.scope = {
github csxiaoyaojianxian / JavaScriptStudy / 09-Tools / 01-webpack / node_modules / webpack / lib / Parser.js View on Github external
let ast;
		const comments = [];
		for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
			if(!ast) {
				try {
					comments.length = 0;
					POSSIBLE_AST_OPTIONS[i].onComment = comments;
					ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
				} catch(e) {
					// ignore the error
				}
			}
		}
		if(!ast) {
			// for the error
			ast = acorn.parse(source, {
				ranges: true,
				locations: true,
				ecmaVersion: ECMA_VERSION,
				sourceType: "module",
				plugins: {
					dynamicImport: true
				},
				onComment: comments
			});
		}
		if(!ast || typeof ast !== "object")
			throw new Error("Source couldn't be parsed");
		const oldScope = this.scope;
		const oldState = this.state;
		const oldComments = this.comments;
		this.scope = {
github abhaydoke09 / Deep-Learning-For-Surveillance / FrontEnd / node_modules / webpack / lib / Parser.js View on Github external
let ast;
		const comments = [];
		for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
			if(!ast) {
				try {
					comments.length = 0;
					POSSIBLE_AST_OPTIONS[i].onComment = comments;
					ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
				} catch(e) {
					// ignore the error
				}
			}
		}
		if(!ast) {
			// for the error
			ast = acorn.parse(source, {
				ranges: true,
				locations: true,
				ecmaVersion: ECMA_VERSION,
				sourceType: "module",
				plugins: {
					dynamicImport: true
				},
				onComment: comments
			});
		}
		if(!ast || typeof ast !== "object")
			throw new Error("Source couldn't be parsed");
		const oldScope = this.scope;
		const oldState = this.state;
		const oldComments = this.comments;
		this.scope = {
github TYRMars / ES6-StepPitGuide / es6 / node_modules / webpack / lib / Parser.js View on Github external
parse(source, initialState) {
		let ast;
		const comments = [];
		for(let i = 0, len = POSSIBLE_AST_OPTIONS.length; i < len; i++) {
			if(!ast) {
				try {
					comments.length = 0;
					POSSIBLE_AST_OPTIONS[i].onComment = comments;
					ast = acorn.parse(source, POSSIBLE_AST_OPTIONS[i]);
				} catch(e) {
					// ignore the error
				}
			}
		}
		if(!ast) {
			// for the error
			ast = acorn.parse(source, {
				ranges: true,
				locations: true,
				ecmaVersion: ECMA_VERSION,
				sourceType: "module",
				plugins: {
					dynamicImport: true
				},
				onComment: comments
github oligot / rollup-plugin-nodent / index.js View on Github external
onParserInstallation(acorn) {
						if (options.onParserInstallation) {
							options.onParserInstallation(acorn);
						}
						// Patch acorn to support dynamic import
						// eslint-disable-next-line import/no-extraneous-dependencies
						require('acorn-dynamic-import/lib/inject').default(acorn);
					}
				})
github ampproject / rollup-plugin-closure-compiler / src / types.ts View on Github external
*
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { OutputOptions, TransformSourceDescription, PluginContext, InputOptions } from 'rollup';
const dynamicImport = require('acorn-dynamic-import');

// @see https://github.com/estree/estree/blob/master/es2015.md#imports
export const IMPORT_DECLARATION = 'ImportDeclaration';
export const DYNAMIC_IMPORT_DECLARATION = dynamicImport.DynamicImportKey;
export const IMPORT_SPECIFIER = 'ImportSpecifier';
export const IMPORT_DEFAULT_SPECIFIER = 'ImportDefaultSpecifier';
export const IMPORT_NAMESPACE_SPECIFIER = 'ImportNamespaceSpecifier';

// @see https://github.com/estree/estree/blob/master/es2015.md#exports
export const EXPORT_NAMED_DECLARATION = 'ExportNamedDeclaration';
export const EXPORT_SPECIFIER = 'ExportSpecifier';
export const EXPORT_DEFAULT_DECLARATION = 'ExportDefaultDeclaration';
export const EXPORT_ALL_DECLARATION = 'ExportAllDeclaration';
export const ALL_EXPORT_DECLARATIONS = [
  EXPORT_NAMED_DECLARATION,
  EXPORT_DEFAULT_DECLARATION,
  EXPORT_ALL_DECLARATION,
];

export type Range = [number, number];
github ColdDay / touchRobot / node_modules / webpack / lib / Parser.js View on Github external
Author Tobias Koppers @sokra
*/
"use strict";

// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API

const acorn = require("acorn");
const acornDynamicImport = require("acorn-dynamic-import").default;
const { Tapable, SyncBailHook, HookMap } = require("tapable");
const util = require("util");
const vm = require("vm");
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
const StackedSetMap = require("./util/StackedSetMap");
const TrackingSet = require("./util/TrackingSet");

const acornParser = acorn.Parser.extend(acornDynamicImport);

const joinRanges = (startRange, endRange) => {
	if (!endRange) return startRange;
	if (!startRange) return endRange;
	return [startRange[0], endRange[1]];
};

const defaultParserOptions = {
	ranges: true,
	locations: true,
	ecmaVersion: 2019,
	sourceType: "module",
	onComment: null
};

// regexp to match at lease one "magic comment"
github flaviuse / mern-authentication / client / node_modules / webpack / lib / Parser.js View on Github external
Author Tobias Koppers @sokra
*/
"use strict";

// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API

const acorn = require("acorn");
const acornDynamicImport = require("acorn-dynamic-import").default;
const { Tapable, SyncBailHook, HookMap } = require("tapable");
const util = require("util");
const vm = require("vm");
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
const StackedSetMap = require("./util/StackedSetMap");
const TrackingSet = require("./util/TrackingSet");

const acornParser = acorn.Parser.extend(acornDynamicImport);

const joinRanges = (startRange, endRange) => {
	if (!endRange) return startRange;
	if (!startRange) return endRange;
	return [startRange[0], endRange[1]];
};

const defaultParserOptions = {
	ranges: true,
	locations: true,
	ecmaVersion: 2019,
	sourceType: "module",
	onComment: null
};

// regexp to match at lease one "magic comment"
github xxxgitone / learningProcess / WebPack-Beginner / node_modules / webpack / lib / Parser.js View on Github external
evaluate(source) {
		const ast = acorn.parse("(" + source + ")", {
			ranges: true,
			locations: true,
			ecmaVersion: ECMA_VERSION,
			sourceType: "module",
			plugins: {
				dynamicImport: true
			}
		});
		if(!ast || typeof ast !== "object" || ast.type !== "Program")
			throw new Error("evaluate: Source couldn't be parsed");
		if(ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement")
			throw new Error("evaluate: Source is not a expression");
		return this.evaluateExpression(ast.body[0].expression);
	}