The following program.
require('prettier').format('<?=2;', { parser: 'php', plugins: [require('@prettier/plugin-php')] })
causes an exception
TypeError: Cannot read property 'includes' of undefined
at printLines (node_modules/@prettier/plugin-php/src/printer.js:1077:31)
at printNode (node_modules/@prettier/plugin-php/src/printer.js:1559:11)
at Object.genericPrint [as print] (node_modules/@prettier/plugin-php/src/printer.js:116:32)
at callPluginPrintFunction (node_modules/prettier/index.js:12984:18)
This is caused by the following code:
const between = options.originalText.trim().match(/^<\?(php|=)(\s+)?\S/);
const afterOpenTag = concat([
between && between[2].includes("\n")
? concat([
hardline,
between[2].split("\n").length > 2 ? hardline : ""
])
: " ",
node.comments ? comments.printComments(node.comments, options) : ""
]);
The second match is optional because of ? character, but things crash if it actually becomes optional.
The following program.
causes an exception
This is caused by the following code:
The second match is optional because of
?character, but things crash if it actually becomes optional.