Skip to content

Commit

Permalink
Deps: Update @babel/generator dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 17, 2023
1 parent 3786de4 commit 5a784ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
23 changes: 13 additions & 10 deletions lib/serialize/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Modules
const {join: pathJoin, relative: pathRelative, dirname} = require('path').posix,
{CodeGenerator} = require('@babel/generator'),
Printer = require('@babel/generator/lib/printer.js').default,
sourceMapFromObject = require('convert-source-map').fromObject,
last = require('lodash/last'),
t = require('@babel/types');
Expand All @@ -26,6 +27,8 @@ const uniformHashPlaceholder = HASH_PLACEHOLDER_CHAR.repeat(HASH_LENGTH),

// Exports

const {StringLiteral: printStingLiteral, Program: printProgram} = Printer.prototype;

module.exports = {
/**
* Output to files.
Expand Down Expand Up @@ -296,27 +299,27 @@ module.exports = {
shouldPrintComment: options.shouldPrintComment
},
sourceMaps ? this.sourceFiles : undefined
)._generator;
);

const printer = new Printer(generator._format, generator._map);

// Shim generator's `StringLiteral` method to capture positions of import paths
const {StringLiteral} = generator;
generator.StringLiteral = function(strNode) {
// Shim printer's `StringLiteral` method to capture positions of import paths
printer.StringLiteral = function(strNode) {
const startPos = this._buf._str.length; // NB: A space may be inserted after this
StringLiteral.call(this, strNode);
printStingLiteral.call(this, strNode);
if (strNode[STRING_POSITIONS]) strNode[STRING_POSITIONS].push([startPos, this._buf._str.length]);
};

if (minify) {
// Patch generator to remove final semi-colon if not required
// Patch printer to remove final semi-colon if not required
// TODO: Remove this if https://github.com/babel/babel/issues/14160 is resolved
const {Program} = generator;
generator.Program = function(programNode) {
Program.call(this, programNode);
printer.Program = function(programNode) {
printProgram.call(this, programNode);
this._buf.removeLastSemicolon();
};
}

const {code: js, map} = generator.generate();
const {code: js, map} = printer.generate(node);
return {js, map};
},

Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@babel/core": "^7.23.5",
"@babel/generator": "^7.23.5",
"@babel/generator": "^7.23.6",
"@babel/helper-module-transforms": "^7.23.3",
"@babel/parser": "^7.23.5",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
Expand Down

0 comments on commit 5a784ad

Please sign in to comment.