Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import assert from "assert";
import * as types from "ast-types";
var namedTypes = types.namedTypes;
var builders = types.builders;
import { parse } from "../lib/parser";
import { Printer } from "../lib/printer";
import { EOL as eol } from "os";
var lines = [
"// file comment",
"exports.foo({",
" // some comment",
" bar: 42,",
" baz: this",
"});"
];
describe("types.visit", function() {
it("replacement", function() {
import assert from "assert";
import * as types from "ast-types";
const n = types.namedTypes;
const isArray = types.builtInTypes.array;
const isObject = types.builtInTypes.object;
import { Lines, concat } from "./lines";
import { comparePos, fixFaultyLocations } from "./util";
import { makeUniqueKey } from "private";
const childNodesCacheKey = makeUniqueKey();
// TODO Move a non-caching implementation of this function into ast-types,
// and implement a caching wrapper function here.
function getSortedChildNodes(node: any, lines: any, resultArray?: any) {
if (!node) {
return;
}
// The .loc checks below are sensitive to some of the problems that
// are fixed by this utility function. Specifically, if it decides to
*/
exports.Emitter = Emitter;
var explodeExpressions = require("./explode-expressions");
var explodeStatements = require("./explode-statements");
var assert = require("assert");
var types = require("ast-types");
var leap = require("../leap");
var meta = require("../meta");
var util = require("../util");
var t = require("../../../../types");
var _ = require("lodash");
var loc = util.loc;
var n = types.namedTypes;
function Emitter(contextId) {
assert.ok(this instanceof Emitter);
t.assertIdentifier(contextId);
// In order to make sure the context object does not collide with
// anything in the local scope, we might have to rename it, so we
// refer to it symbolically instead of just assuming that it will be
// called "context".
this.contextId = contextId;
// An append-only list of Statements that grows each time this.emit is
// called.
this.listing = [];
// A sparse array whose keys correspond to locations in this.listing
import assert from "assert";
import * as recast from "../main";
import { parse } from "../lib/parser";
import { Printer } from "../lib/printer";
import * as types from "ast-types";
const n = types.namedTypes;
const b = types.builders;
import { fromString } from "../lib/lines";
import { EOL as eol } from "os";
const linesModule = require("../lib/lines");
const nodeMajorVersion = parseInt(process.versions.node, 10);
describe("printer", function() {
it("Printer", function testPrinter(done) {
const code = testPrinter + "";
const ast = parse(code);
const printer = new Printer;
assert.strictEqual(typeof printer.print, "function");
assert.strictEqual(printer.print(null).code, "");
let string = printer.printGenerically(ast).code;
"format cjs";
var esprima = require("esprima"),
optionsNormalize = require("./options_normalize"),
getAst = require("./get_ast"),
types = require("ast-types"),
n = types.namedTypes;
var dirnameExp = /__dirname/;
var globalExp = /global/;
module.exports = function(load, options) {
var ast = getAst(load);
var source = load.source;
var cjsOptions = {
hasDirname: dirnameExp.test(source),
hasGlobal: globalExp.test(source),
duplicateCjsDependencies: options.duplicateCjsDependencies
};
cjsOptions.needsFunctionWrapper =
cjsOptions.hasDirname || cjsOptions.hasGlobal;
enter: function enter(node) {
if (_astTypes.namedTypes.FunctionDeclaration.check(node) || _astTypes.namedTypes.FunctionExpression.check(node)) {
return _estraverse.VisitorOption.Skip;
}
if (_astTypes.namedTypes.ThisExpression.check(node)) {
thisExpression = true;
return parser.parseWithLOC("$that");
}
}
});
'use strict';
var assert = require('assert');
var types = require('ast-types').namedTypes;
var build = require('ast-types').builders;
var List = require('immutable').List;
var Map = require('immutable').Map;
var Record = require('immutable').Record;
var Set = require('immutable').Set;
var Syntax = require('estraverse').Syntax;
var parse = require('./parser-combinator');
var analyzeRefs = require('./analyze-refs').analyzeRefs;
var fail = require('../syntax').fail;
var isHeapVar = null;
import assert from "assert";
import * as linesModule from "./lines";
import * as types from "ast-types";
const Printable = types.namedTypes.Printable;
const Expression = types.namedTypes.Expression;
const ReturnStatement = types.namedTypes.ReturnStatement;
const SourceLocation = types.namedTypes.SourceLocation;
import { comparePos, copyPos, getUnionOfKeys } from "./util";
import FastPath from "./fast-path";
const isObject = types.builtInTypes.object;
const isArray = types.builtInTypes.array;
const isString = types.builtInTypes.string;
const riskyAdjoiningCharExp = /[0-9a-z_$]/i;
interface PatcherType {
replace(loc: any, lines: any): any;
get(loc?: any): any;
tryToReprintComments(newNode: any, oldNode: any, print: any): any;
deleteComments(node: any): any;
}
var types = require("ast-types");
var first = require("lodash/first");
var last = require("lodash/last");
var concat = require("lodash/concat");
var estemplate = require("estemplate");
var n = types.namedTypes;
module.exports = function(ast) {
var variableNames = collectVariableNames(ast);
appendToDefineFactory(
ast,
concat(variableNames.map(patchHelperCallTemplate), patchHelperTemplate())
);
return ast;
};
/**
* Collects the identifiers of Babel generated import assignments
*
* E.g, given the AST of the code below:
'use strict';
var assert = require('assert');
var types = require('ast-types').namedTypes;
var build = require('ast-types').builders;
var List = require('immutable').List;
var Map = require('immutable').Map;
var Record = require('immutable').Record;
var Set = require('immutable').Set;
var Stack = require('immutable').Stack;
var Syntax = require('estraverse').Syntax;
var match = require('./match').match;
var clause = require('./match').clause;
var fail = require('../syntax').fail;
var destruct = require('./match-lang');
var parse = require('./parser-combinator');