How to use the astring.generate function in astring

To help you get started, we’ve selected a few astring 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 terser / terser / test / mocha / spidermonkey.js View on Github external
it("should produce an AST compatible with astring", function() {
        var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8");
        var terser_ast = Terser.parse(code);
        var moz_ast = terser_ast.to_mozilla_ast();
        var generated = astring.generate(moz_ast);
        var parsed = acorn.parse(generated, {
            sourceType: "module",
            ecmaVersion: 9
        });
        assert.strictEqual(
            Terser.AST_Node.from_mozilla_ast(parsed).print_to_string(),
            terser_ast.print_to_string()
        );
    });
});
github ghettovoice / vuelayers / build / jsdoc / vue.js View on Github external
case 'ArrayExpression':
        if (!/@type\s.+/.test(evt.comment)) {
          evt.comment = setCommentTag(evt.comment, 'type',
            `{${typeNode.elements.map(n => ctorNameToType(n.name)).join('|')}}`)
        }
        break
      case 'ObjectExpression':
        let typePropNode = typeNode.properties.find(n => n.key.name === 'type')
        let defaultPropNode = typeNode.properties.find(n => n.key.name === 'default')
        let requiredPropNode = typeNode.properties.find(n => n.key.name === 'required')

        if (!typePropNode) return

        handle(typePropNode.value)
        if (defaultPropNode && !/^\s*\*\s@default(?:value)?\s.*$/im.test(evt.comment)) {
          evt.comment = setCommentTag(evt.comment, 'default', generate(defaultPropNode.value))
        }
        if (requiredPropNode) {
          evt.comment = setCommentTag(evt.comment, 'required')
        }
        break
    }
  }
github microsoft / vscode-azure-blockchain-ethereum / src / debugAdapter / configurationReader.ts View on Github external
const provider: IProvider = {
      raw: generate(node),
    };

    const mnemonicNode = node.arguments[0];
    if (mnemonicNode && mnemonicNode.type === 'Literal') {
      provider.mnemonic = '' + mnemonicNode.value;
    }

    const urlNode = node.arguments[1];
    if (urlNode && urlNode.type === 'Literal') {
      provider.url = '' + urlNode.value;
    }

    if (urlNode && urlNode.type !== 'Literal') {
      provider.url = generate(urlNode);
    }

    return provider;
  }
github microsoft / vscode-azure-blockchain-ethereum / src / debugAdapter / configurationReader.ts View on Github external
public writeAST(): void {
      return fs.writeFileSync(this.filePath, generate(this.ast, { comments: true }));
    }
github source-academy / js-slang / src / rules / noIfWithoutElse.ts View on Github external
public elaborate() {
    return stripIndent`
      This "if" block requires corresponding "else" block which will be
      evaluated when ${generate(this.node.test)} expression evaluates to false.

      Later in the course we will lift this restriction and allow "if" without
      else.
    `
  }
}
github source-academy / cadet-frontend / src / slang / interop.ts View on Github external
export const toString = (value: Value, length = 0): string => {
  if (value instanceof ArrowClosure || value instanceof Closure) {
    return generate(value.node)
  } else if (Array.isArray(value)) {
    if (length > MAX_LIST_DISPLAY_LENGTH) {
      return '...'
    } else {
      return arrayToString(value, length)
    }
  } else if (typeof value === 'string') {
    return `\"${value}\"`
  } else if (typeof value === 'undefined') {
    return 'undefined'
  } else if (typeof value === 'function') {
    if (value.__SOURCE__) {
      return `function ${value.__SOURCE__} {\n\t[implementation hidden]\n}`
    } else {
      return stripBody(value.toString())
    }
github source-academy / js-slang / src / interpreter-errors.ts View on Github external
CallExpression(node: any, state: any) {
      state.write(generate(node.callee))
      state.write('(')
      const argsRepr = node.arguments.map((arg: any) => stringify(arg.value))
      state.write(argsRepr.join(', '))
      state.write(')')
    }
  }
github microsoft / vscode-azure-blockchain-ethereum / src / debugAdapter / configurationReader.ts View on Github external
function astToHDWalletProvider(node: ESTree.NewExpression): IProvider {
    const provider: IProvider = {
      raw: generate(node),
    };

    const mnemonicNode = node.arguments[0];
    if (mnemonicNode && mnemonicNode.type === 'Literal') {
      provider.mnemonic = '' + mnemonicNode.value;
    }

    const urlNode = node.arguments[1];
    if (urlNode && urlNode.type === 'Literal') {
      provider.url = '' + urlNode.value;
    }

    if (urlNode && urlNode.type !== 'Literal') {
      provider.url = generate(urlNode);
    }
github microsoft / vscode-azure-blockchain-ethereum / src / helpers / truffleConfig.ts View on Github external
function astToHDWalletProvider(node: ESTree.NewExpression): IProvider {
    const provider: IProvider = {
      raw: generate(node),
    };

    const mnemonicNode = node.arguments[0] as ESTree.NewExpression & ESTree.Literal;
    const mnemonicFilePathNode = mnemonicNode && mnemonicNode.arguments && mnemonicNode.arguments[0] as ESTree.Literal;

    if (isMnemonicNode(mnemonicNode)) {
      provider.mnemonic = mnemonicNode.value as string;
    } else if (isMnemonicNode(mnemonicFilePathNode)) {
      provider.mnemonic = MnemonicRepository.getMnemonic(mnemonicFilePathNode.value as string);
    }

    const urlNode = node.arguments[1];
    if (urlNode && urlNode.type === 'Literal') {
      provider.url = '' + urlNode.value;
    }

astring

JavaScript code generator from an ESTree-compliant AST.

MIT
Latest version published 3 months ago

Package Health Score

88 / 100
Full package analysis

Popular astring functions