Skip to content

Commit

Permalink
feat: retain spaces before /* @if */ and after /* @endif */
Browse files Browse the repository at this point in the history
This is a small breaking change from original preprocess. This new behaviour will help skeleton author to fine control output.
  • Loading branch information
3cp committed Oct 17, 2019
1 parent c10713c commit 8388bb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/preprocess/regex-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.js = {
'//[ \t]*@eval[ \t]+(.*?)[ \t]*$'
],
if: {
start: '[ \t]*(?://|/\\*)[ \t]*@if[ \t]+([^\n*]*)(?:\\*(?:\\*|/))?(?:[ \t]*\n+)?',
end : '[ \t]*(?://|/\\*)[ \t]*@endif[ \t]*(?:\\*(?:\\*|/))?(?:[ \t]*\n)?'
start: '(?:[ \t]*//|/\\*)[ \t]*@if[ \t]+([^\n*]*)(?:(?:\\*(?:\\*|/))|(?:[ \t]*\n+))',
end : '(?:[ \t]*//|/\\*)[ \t]*@endif[ \t]*(?:(?:\\*(?:\\*|/))|(?:[ \t]*\n))'
},
};
22 changes: 9 additions & 13 deletions test/preprocess/if.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ b
/* @endif */
c`;

t.is(preprocess(source, null, ['foo']), 'a\nb\nc');
t.is(preprocess(source, null, ['bar']), 'a\nc');
t.is(preprocess(source, null, ['foo']), 'a\n\nb\n\nc');
t.is(preprocess(source, null, ['bar']), 'a\n\nc');
});

test('@if complains about missing ending in js syntax with hidden syntax (block comment)', t => {
Expand All @@ -117,25 +117,21 @@ test('@if supports one line block comment in js syntax', t => {
});

test('@if supports nesting (block comment) in js syntax', t => {
const source = 'a/* @if foo */b/* @if bar */bad/* @endif */c/* @if foo */d/* @endif */e/* @endif */f';
t.is(preprocess(source, null, ['foo']), 'abcdef');
t.is(preprocess(source, null, ['bar']), 'af');
t.is(preprocess(source, null, ['foo', 'bar']), 'abbadcdef');
const source = 'a /* @if foo */b/* @if bar */bad/* @endif */ c/* @if foo */d/* @endif */e/* @endif */f';
t.is(preprocess(source, null, ['foo']), 'a b cdef');
t.is(preprocess(source, null, ['bar']), 'a f');
t.is(preprocess(source, null, ['foo', 'bar']), 'a bbad cdef');
});

test('@if supports nested condition in js syntax', t => {
const source = `a
// @if foo
b
// @if bar && xx
d
/* @if lo */
e
/* @endif */
d/* @if lo */
e/* @endif */
// @endif
/* @if xx **
f
/* @endif */
/* @if xx **f/* @endif */
// @endif
c`;

Expand Down

0 comments on commit 8388bb6

Please sign in to comment.