Skip to content

Commit

Permalink
Replace Array.push(...spread) in micromark helpers with Array.concat …
Browse files Browse the repository at this point in the history
…to avoid risk of stack overflow.
  • Loading branch information
DavidAnson committed Sep 5, 2023
1 parent 07f4031 commit a7dfa4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 3 additions & 5 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,10 +1169,6 @@ module.exports = {

// @ts-ignore
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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 _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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
Expand Down Expand Up @@ -1326,7 +1322,9 @@ function micromarkParseWithOffset(markdown, micromarkOptions, referencesDefined,
var reparseMarkdown = lines.slice(current.startLine - 1, current.endLine).join("\n");
var tokens = micromarkParseWithOffset(reparseMarkdown, reparseOptions, referencesDefined, current.startLine - 1);
current.children = tokens;
flatTokens.push.apply(flatTokens, _toConsumableArray(tokens[flatTokensSymbol]));
// Avoid stack overflow of Array.push(...spread)
// eslint-disable-next-line unicorn/prefer-spread
flatTokens = flatTokens.concat(tokens[flatTokensSymbol]);
}
} else if (kind === "exit") {
if (type === "htmlFlow") {
Expand Down
6 changes: 4 additions & 2 deletions helpers/micromark.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function micromarkParseWithOffset(

// Create Token objects
const document = [];
const flatTokens = [];
let flatTokens = [];
let current = {
"children": document
};
Expand Down Expand Up @@ -161,7 +161,9 @@ function micromarkParseWithOffset(
current.startLine - 1
);
current.children = tokens;
flatTokens.push(...tokens[flatTokensSymbol]);
// Avoid stack overflow of Array.push(...spread)
// eslint-disable-next-line unicorn/prefer-spread
flatTokens = flatTokens.concat(tokens[flatTokensSymbol]);
}
} else if (kind === "exit") {
if (type === "htmlFlow") {
Expand Down

0 comments on commit a7dfa4b

Please sign in to comment.