Skip to content

Commit d39895d

Browse files
committed
GH#3 / RT#108682 - verify that preserved line comments get EOL
When a line comment is preserved as it contains a copyright, it should be immediately followed by an EOL character. Test and verify that this is the case.
1 parent 039ae86 commit d39895d

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Revision history for Perl extension JavaScript::Minifier::XS.
55
- optimized memory allocations, by allocating Nodes in bulk, and being
66
smarter about when we need to free/reallocate content buffers in Nodes
77
- optimize whitespace collapsing
8+
- GH#3 / RT#108682; fix whitespace reduction at end of preserved line
9+
comment. Thanks to Dan Goodliffe
810

911
0.13 2020-12-30 21:46:29-08:00 America/Vancouver
1012
- POD cleanups; spelling, SYNOPSIS

XS.xs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ int JsCanPrune(Node* node) {
599599
if (nodeIsPREFIXSIGIL(node) && next && nodeIsWHITESPACE(next))
600600
return PRUNE_NEXT;
601601
/* remove whitespace before "postfix" sigils */
602-
if (nodeIsPOSTFIXSIGIL(node) && prev && nodeIsWHITESPACE(prev))
602+
if (nodeIsPOSTFIXSIGIL(node) && prev && nodeIsWHITESPACE(prev) && prev->prev && !nodeIsLINECOMMENT(prev->prev))
603603
return PRUNE_PREVIOUS;
604604
/* remove whitespace (but NOT endspace) after closing brackets */
605605
if (next && nodeIsWHITESPACE(next) && !nodeIsENDSPACE(next) && (nodeIsCHAR(node,')') || nodeIsCHAR(node,'}') || nodeIsCHAR(node,']')))

t/minify.t

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ subtest 'comments' => sub {;
5151
is $got, $expect;
5252
};
5353

54+
subtest 'preserved copyright line comment gets EOL' => sub { # GH#3
55+
my $given = q|
56+
function foo() {
57+
// copyright is preserved
58+
}
59+
|;
60+
my $expect = qq|function foo(){// copyright is preserved\n}|;
61+
my $got = minify($given);
62+
is $got, $expect;
63+
};
64+
5465
subtest 'inline block comment' => sub {
5566
my $given = 'var foo /* remove */ = /* me too */ 3;';
5667
my $expect = 'var foo=3;';

0 commit comments

Comments
 (0)