How to use the babel-generator/lib/printer.prototype function in babel-generator

To help you get started, we’ve selected a few babel-generator 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 nikaspran / coffee-to-ts / src / babel / import.js View on Github external
babelTypes.FLIPPED_ALIAS_KEYS.Expression.push('TypeAssertedExpression');

Printer.prototype.ImportRequire = function (node) {
	this.word('import');
	this.print(node.local, node);
	this.space();
	this.token('=');
	this.space();
	this.word('require');
	this.token('(');
	this.print(node.source, node);
	this.token(')');
	this.semicolon();
};

Printer.prototype.TypeAssertedExpression = function (node) {
	this.print(node.assertion, node);
	this.space();
	this.print(node.expression, node);
};

Printer.prototype.TypeAssertion = function (node) {
	this.token('<');
	this.word(node.value);
	this.token('>');
};

Parser.prototype.tsParseImportRequire = function (node) {
	this.next();
	node.local = this.parseIdentifier();

	this.eat(types.eq);
github nikaspran / coffee-to-ts / src / babel / import.js View on Github external
import Parser from "babylon/lib/parser";
import {types} from 'babylon/lib/tokenizer/types';
import Printer from 'babel-generator/lib/printer';
import * as babelTypes from 'babel-types';

babelTypes.TYPES.push('ImportRequire');
babelTypes.FLIPPED_ALIAS_KEYS.Expression.push('TypeAssertedExpression');

Printer.prototype.ImportRequire = function (node) {
	this.word('import');
	this.print(node.local, node);
	this.space();
	this.token('=');
	this.space();
	this.word('require');
	this.token('(');
	this.print(node.source, node);
	this.token(')');
	this.semicolon();
};

Printer.prototype.TypeAssertedExpression = function (node) {
	this.print(node.assertion, node);
	this.space();
	this.print(node.expression, node);
github nikaspran / coffee-to-ts / src / babel / import.js View on Github external
this.token('=');
	this.space();
	this.word('require');
	this.token('(');
	this.print(node.source, node);
	this.token(')');
	this.semicolon();
};

Printer.prototype.TypeAssertedExpression = function (node) {
	this.print(node.assertion, node);
	this.space();
	this.print(node.expression, node);
};

Printer.prototype.TypeAssertion = function (node) {
	this.token('<');
	this.word(node.value);
	this.token('>');
};

Parser.prototype.tsParseImportRequire = function (node) {
	this.next();
	node.local = this.parseIdentifier();

	this.eat(types.eq);
	this.eatContextual('require');
	this.eat(types.parenL);

	node.source = this.match(types.string) ? this.parseExprAtom() : this.unexpected();
	this.eat(types.parenR);
	this.semicolon();

babel-generator

Turns an AST into code.

MIT
Latest version published 6 years ago

Package Health Score

88 / 100
Full package analysis

Similar packages