Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/@babel/generator/lib/index.js
rd565449 r0c6b92a 7 7 var _sourceMap = require("./source-map.js"); 8 8 var _printer = require("./printer.js"); 9 function normalizeOptions(code, opts) { 9 function normalizeOptions(code, opts, ast) { 10 if (opts.experimental_preserveFormat) { 11 if (typeof code !== "string") { 12 throw new Error("`experimental_preserveFormat` requires the original `code` to be passed to @babel/generator as a string"); 13 } 14 if (!opts.retainLines) { 15 throw new Error("`experimental_preserveFormat` requires `retainLines` to be set to `true`"); 16 } 17 if (opts.compact && opts.compact !== "auto") { 18 throw new Error("`experimental_preserveFormat` is not compatible with the `compact` option"); 19 } 20 if (opts.minified) { 21 throw new Error("`experimental_preserveFormat` is not compatible with the `minified` option"); 22 } 23 if (opts.jsescOption) { 24 throw new Error("`experimental_preserveFormat` is not compatible with the `jsescOption` option"); 25 } 26 if (!Array.isArray(ast.tokens)) { 27 throw new Error("`experimental_preserveFormat` requires the AST to have attatched the token of the input code. Make sure to enable the `tokens: true` parser option."); 28 } 29 } 10 30 const format = { 11 31 auxiliaryCommentBefore: opts.auxiliaryCommentBefore, 12 32 auxiliaryCommentAfter: opts.auxiliaryCommentAfter, 13 33 shouldPrintComment: opts.shouldPrintComment, 34 preserveFormat: opts.experimental_preserveFormat, 14 35 retainLines: opts.retainLines, 15 36 retainFunctionParens: opts.retainFunctionParens, … … 48 69 } 49 70 } 50 if (format.compact ) {71 if (format.compact || format.preserveFormat) { 51 72 format.indent.adjustMultilineComment = false; 52 73 } … … 71 92 this._map = void 0; 72 93 this._ast = ast; 73 this._format = normalizeOptions(code, opts );94 this._format = normalizeOptions(code, opts, ast); 74 95 this._map = opts.sourceMaps ? new _sourceMap.default(opts, code) : null; 75 96 } … … 81 102 } 82 103 function generate(ast, opts = {}, code) { 83 const format = normalizeOptions(code, opts );104 const format = normalizeOptions(code, opts, ast); 84 105 const map = opts.sourceMaps ? new _sourceMap.default(opts, code) : null; 85 const printer = new _printer.default(format, map );106 const printer = new _printer.default(format, map, ast.tokens, typeof code === "string" ? code : null); 86 107 return printer.generate(ast); 87 108 }
Note:
See TracChangeset
for help on using the changeset viewer.