Conversation
lib/console.js
Outdated
There was a problem hiding this comment.
You can also check for \n first by adding a indexOf guard. Using indexOf for cases were there is no newline it is a lot faster and almost negligible in case there is one.
if (groupIndent.length !== 0 && string.indexOf("\n") !== -1) {
// ...
(Yes, indexOf is still faster then includes)
There was a problem hiding this comment.
I'd have to move the prepending of groupIndent if I did that so the result would probably be:
if (groupIndent.length !== 0) {
if (string.indexOf('\n') !== -1 {
string = string.replace(/\n/g, `\n${groupIndent}`);
}
string = groupIndent + string;
}
string += '\n';...or...
if (groupIndent.length !== 0 && string.indexOf("\n") !== -1) {
string = string.replace(/\n/g, `\n${groupIndent}`);
}
string = groupIndent + string + '\n';There was a problem hiding this comment.
I would do the latter while I would actually not replace the string again but simply place it like this
if (!ignoreErrors) return stream.write(`${groupIndent}${string}\n`);There was a problem hiding this comment.
(I went with the first option in my above comment.)
|
@Trott just a thought - what do you think about hiding and protecting the Symbol a bit? |
There was a problem hiding this comment.
The reason why I didn't suggest this on the original PR is that we can go down the rabbit hole real quick with this kind of changes. For one, I can see a legitimate argument to handle '\r\n' and even '\r'. If we do handle them, we might need to adjust column width etc. for modules that are e.g. curses work-alikes using \r. And the list goes on.
I'd prefer to keep group() minimal.
|
@TimothyGu I would suggest to keep the implementation similar to the ones used in browsers. I do not think we should support |
|
@TimothyGu I agree that there's a rabbit-hole danger, but this seems pretty important IMO considering |
Preserve indentation for multiline strings, objects that span multiple lines, etc.
Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable.
8858cc8 to
9df027b
Compare
Preserve indentation for multiline strings, objects that span multiple lines, etc. also make groupIndent non-enumerable Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable. PR-URL: #14999 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
|
Landed in af11867 |
Preserve indentation for multiline strings, objects that span multiple lines, etc. also make groupIndent non-enumerable Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable. PR-URL: nodejs/node#14999 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Preserve indentation for multiline strings, objects that span multiple lines, etc. also make groupIndent non-enumerable Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable. PR-URL: nodejs/node#14999 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
|
Setting as don't land as @Trott please change label if neccessary |
Changed! :-D |
Preserve indentation for multiline strings, objects that span multiple lines, etc. also make groupIndent non-enumerable Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable. PR-URL: #14999 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Preserve indentation for multiline strings, objects that span multiple lines, etc. also make groupIndent non-enumerable Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable. PR-URL: #14999 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Preserve indentation for multiline strings, objects that span multiple lines, etc. also make groupIndent non-enumerable Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable. PR-URL: #14999 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Preserve indentation for multiline strings, objects that span multiple lines, etc. also make groupIndent non-enumerable Hide the internal `groupIndent` key a bit by making it non-enumerable and non-configurable. PR-URL: #14999 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
|
This does not land cleanly in LTS. Please feel free to manually backport by following the guide. Please also feel free to replace do-not-land if it is being backported |
Preserve indentation for multiline strings, objects that span multiple
lines, etc.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
console
/cc @BridgeAR