sql-formatter
Advanced tools
Comparing version 10.5.1 to 10.6.0
@@ -18,4 +18,2 @@ "use strict"; | ||
var _InlineBlock = _interopRequireDefault(require("./InlineBlock")); | ||
var _Layout = require("./Layout"); | ||
@@ -25,2 +23,4 @@ | ||
var _InlineLayout = _interopRequireWildcard(require("./InlineLayout")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -30,4 +30,14 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -54,4 +64,2 @@ | ||
_defineProperty(this, "inlineBlock", void 0); | ||
_defineProperty(this, "params", void 0); | ||
@@ -69,3 +77,2 @@ | ||
this.inline = inline; | ||
this.inlineBlock = new _InlineBlock["default"](this.cfg.expressionWidth); | ||
this.params = params; | ||
@@ -168,7 +175,11 @@ this.layout = layout; | ||
value: function formatParenthesis(node) { | ||
var inline = this.inlineBlock.isInlineBlock(node); | ||
var inlineLayout = this.formatInlineExpression(node.children); | ||
if (inline) { | ||
if (inlineLayout) { | ||
var _this$layout; | ||
this.layout.add(node.openParen); | ||
this.layout = this.formatSubExpression(node.children, inline); | ||
(_this$layout = this.layout).add.apply(_this$layout, _toConsumableArray(inlineLayout.getLayoutItems())); | ||
this.layout.add(_Layout.WS.NO_SPACE, node.closeParen, _Layout.WS.SPACE); | ||
@@ -180,7 +191,7 @@ } else { | ||
this.layout.add(_Layout.WS.INDENT); | ||
this.layout = this.formatSubExpression(node.children, inline); | ||
this.layout = this.formatSubExpression(node.children); | ||
} else { | ||
this.layout.indentation.increaseBlockLevel(); | ||
this.layout.add(_Layout.WS.INDENT); | ||
this.layout = this.formatSubExpression(node.children, inline); | ||
this.layout = this.formatSubExpression(node.children); | ||
this.layout.indentation.decreaseBlockLevel(); | ||
@@ -350,3 +361,2 @@ } | ||
value: function formatSubExpression(nodes) { | ||
var inline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.inline; | ||
return new ExpressionFormatter({ | ||
@@ -356,6 +366,32 @@ cfg: this.cfg, | ||
layout: this.layout, | ||
inline: inline | ||
inline: this.inline | ||
}).format(nodes); | ||
} | ||
}, { | ||
key: "formatInlineExpression", | ||
value: function formatInlineExpression(nodes) { | ||
var oldParamIndex = this.params.getPositionalParameterIndex(); | ||
try { | ||
return new ExpressionFormatter({ | ||
cfg: this.cfg, | ||
params: this.params, | ||
layout: new _InlineLayout["default"](this.cfg.expressionWidth), | ||
inline: true | ||
}).format(nodes); | ||
} catch (e) { | ||
if (e instanceof _InlineLayout.InlineLayoutError) { | ||
// While formatting, some of the positional parameters might have | ||
// been consumed, which increased the current parameter index. | ||
// We reset the index to an earlier state, so we can run the | ||
// formatting again and re-consume these parameters in non-inline mode. | ||
this.params.setPositionalParameterIndex(oldParamIndex); | ||
return undefined; | ||
} else { | ||
// forward all unexpected errors | ||
throw e; | ||
} | ||
} | ||
} | ||
}, { | ||
key: "formatKeywordNode", | ||
@@ -362,0 +398,0 @@ value: function formatKeywordNode(node) { |
@@ -152,3 +152,12 @@ "use strict"; | ||
} | ||
/** | ||
* Returns the internal layout data | ||
*/ | ||
}, { | ||
key: "getLayoutItems", | ||
value: function getLayoutItems() { | ||
return this.items; | ||
} | ||
}, { | ||
key: "itemToString", | ||
@@ -155,0 +164,0 @@ value: function itemToString(item) { |
@@ -20,5 +20,2 @@ "use strict"; | ||
var Params = /*#__PURE__*/function () { | ||
/** | ||
* @param {ParamItems} params | ||
*/ | ||
function Params(params) { | ||
@@ -55,2 +52,20 @@ _classCallCheck(this, Params); | ||
} | ||
/** | ||
* Returns index of current positional parameter. | ||
*/ | ||
}, { | ||
key: "getPositionalParameterIndex", | ||
value: function getPositionalParameterIndex() { | ||
return this.index; | ||
} | ||
/** | ||
* Sets index of current positional parameter. | ||
*/ | ||
}, { | ||
key: "setPositionalParameterIndex", | ||
value: function setPositionalParameterIndex(i) { | ||
this.index = i; | ||
} | ||
}]); | ||
@@ -57,0 +72,0 @@ |
@@ -14,3 +14,2 @@ import { FormatOptions } from "../FormatOptions"; | ||
private cfg; | ||
private inlineBlock; | ||
private params; | ||
@@ -42,2 +41,3 @@ private layout; | ||
private formatSubExpression; | ||
private formatInlineExpression; | ||
private formatKeywordNode; | ||
@@ -44,0 +44,0 @@ private formatJoin; |
@@ -36,3 +36,7 @@ import Indentation from './Indentation'; | ||
toString(): string; | ||
/** | ||
* Returns the internal layout data | ||
*/ | ||
getLayoutItems(): LayoutItem[]; | ||
private itemToString; | ||
} |
@@ -8,7 +8,4 @@ export declare type ParamItems = { | ||
export default class Params { | ||
/** | ||
* @param {ParamItems} params | ||
*/ | ||
params: ParamItems | string[] | undefined; | ||
index: number; | ||
private params; | ||
private index; | ||
constructor(params: ParamItems | string[] | undefined); | ||
@@ -22,2 +19,10 @@ /** | ||
}): string; | ||
/** | ||
* Returns index of current positional parameter. | ||
*/ | ||
getPositionalParameterIndex(): number; | ||
/** | ||
* Sets index of current positional parameter. | ||
*/ | ||
setPositionalParameterIndex(i: number): void; | ||
} |
@@ -76,3 +76,3 @@ import { TokenType } from "../lexer/token"; | ||
object: AstNode; | ||
property: IdentifierNode; | ||
property: IdentifierNode | ArraySubscriptNode | AllColumnsAsteriskNode; | ||
}; | ||
@@ -79,0 +79,0 @@ export declare type IdentifierNode = { |
{ | ||
"name": "sql-formatter", | ||
"version": "10.5.1", | ||
"version": "10.6.0", | ||
"description": "Format whitespace in a SQL query to make it more readable", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1962004
8602