UNPKG

ecmarkup

Version:

Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.

33 lines (32 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const utils_1 = require("../../utils"); const ruleId = 'prefer-throw-shorthand'; /* Checks that "return ThrowCompletion(...)" is written using the "throw" shorthand. Does not flag ThrowCompletion when its result is assigned to an alias. */ function default_1(report, step, algorithmSource, parsedSteps) { const stepSeq = parsedSteps.get(step); if (stepSeq == null) { return; } const items = stepSeq.items; for (let i = 1; i < items.length; ++i) { const item = items[i]; if (item.name === 'call' && item.callee.length === 1 && item.callee[0].name === 'text' && item.callee[0].contents === 'ThrowCompletion') { const prev = items[i - 1]; if (prev.name === 'text' && /\breturn\s+$/i.test(prev.contents)) { report({ ruleId, message: 'prefer "throw _x_" over "return ThrowCompletion(_x_)"', ...(0, utils_1.offsetToLineAndColumn)(algorithmSource, item.callee[0].location.start.offset), }); } } } }