Summary
According to the type definition, the user can omit the opts argument of Node#rangeBy().
|
opts?: Pick<WarningOptions, 'endIndex' | 'index' | 'word'> |
However, if it is omitted, Node#rangeBy()/Node#positionBy() will throw an error.
Reproduction
https://stackblitz.com/edit/stackblitz-starters-moxcrard?file=index.ts&view=editor
index.ts:
import { parse, Rule } from 'postcss';
const css = parse('a { one: X }');
const a = css.first as Rule;
console.log(a.rangeBy()); // or `console.log(a.positionBy());`
When a.rangeBy() is called, the result is as follows:
$ ts-node index.ts
/home/projects/stackblitz-starters-moxcrard/node_modules/postcss/lib/node.js:271
if (opts.word) {
^
TypeError: Cannot read properties of undefined (reading 'word')
at Rule.rangeBy (/home/projects/stackblitz-starters-moxcrard/node_modules/postcss/lib/node.js:271:14)
at Object.eval (/home/projects/stackblitz-starters-moxcrard/index.ts:6:15)
at Object._0x2b1965 (https://stackblitzstartersmoxcrard-tnaw-0o4eivqm.w-credentialless-staticblitz.com/blitz.5a421e5b.js:40:815191)
at Module._compile (node:internal/modules/cjs/loader:144:14246)
at m._compile (/home/projects/stackblitz-starters-moxcrard/node_modules/ts-node/dist/index.js:857:29)
at Module._extensions..js (node:internal/modules/cjs/loader:144:14855)
at require.extensions.<computed> (/home/projects/stackblitz-starters-moxcrard/node_modules/ts-node/dist/index.js:859:16)
at Module.load (node:internal/modules/cjs/loader:144:12820)
at Module._load (node:internal/modules/cjs/loader:144:10273)
at Module.executeUserEntryPoint (node:internal/modules/run_main:165:1641)
When a.positionBy() is called, the result is as follows:
$ ts-node index.ts
/home/projects/stackblitz-starters-moxcrard/node_modules/postcss/lib/node.js:213
if (opts.index) {
^
TypeError: Cannot read properties of undefined (reading 'index')
at Rule.positionBy (/home/projects/stackblitz-starters-moxcrard/node_modules/postcss/lib/node.js:213:14)
at Object.eval (/home/projects/stackblitz-starters-moxcrard/index.ts:6:15)
at Object._0x2b1965 (https://stackblitzstartersmoxcrard-tnaw-0o4eivqm.w-credentialless-staticblitz.com/blitz.5a421e5b.js:40:815191)
at Module._compile (node:internal/modules/cjs/loader:144:14246)
at m._compile (/home/projects/stackblitz-starters-moxcrard/node_modules/ts-node/dist/index.js:857:29)
at Module._extensions..js (node:internal/modules/cjs/loader:144:14855)
at require.extensions.<computed> (/home/projects/stackblitz-starters-moxcrard/node_modules/ts-node/dist/index.js:859:16)
at Module.load (node:internal/modules/cjs/loader:144:12820)
at Module._load (node:internal/modules/cjs/loader:144:10273)
at Module.executeUserEntryPoint (node:internal/modules/run_main:165:1641)
Expect Behavior
No error is thrown.
Additional Context
Summary
According to the type definition, the user can omit the
optsargument ofNode#rangeBy().postcss/lib/node.d.ts
Line 427 in 25443a5
However, if it is omitted,
Node#rangeBy()/Node#positionBy()will throw an error.Reproduction
https://stackblitz.com/edit/stackblitz-starters-moxcrard?file=index.ts&view=editor
index.ts:When
a.rangeBy()is called, the result is as follows:When
a.positionBy()is called, the result is as follows:Expect Behavior
No error is thrown.
Additional Context
CssSyntaxError.offsetandCssSyntaxError.endOffset#2022.optsindicates.