Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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 = {
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 = {
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 = {
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
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);
}
})
*
* 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];
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"
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"
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);
}