infernojs / babel-plugin-inferno

Transforms JSX to InfernoJS vNodes
MIT License
79 stars 26 forks source link

Simplified regex to pass tests #33

Closed aaren-cordova closed 7 years ago

trueadm commented 7 years ago

@nightwolfz please can your code review too?

nightwolfz commented 7 years ago

This regex leaves a single empty space/tab at beginning and the end. Is that the behavior we want ?

lukeed commented 7 years ago

IIRC, we want to leave a space at the end only so that Hello world, retains its trailing space.

nightwolfz commented 7 years ago

Some "failing" examples

const regex = /\s{2,}/g

`\nBlow your mind\n`.replace(regex, ' ');    // leaves new line at beginning/end
`\nBlow\n your\n mind\n`.replace(regex, ''); // Blowyourmind => removes new lines and spaces
`\t Blow\t your  mind`.replace(regex, '');   // Blowyourmind => removes all spaces
` \t Blow your mind \t`.replace(regex, '');  // doesn't leave space at the beginning and end

I think they should all give the same output

aaren-cordova commented 7 years ago

Awesome, I was relying solely on the tests to define the bounds of what is proper input and output text. I'll update it to include the failing examples @nightwolfz mentioned.

aaren-cordova commented 7 years ago

Getting a few tests failing, but I'm not quite sure they line up with the above comment. Tests like: <div class="tab-group">inlineText\t</div> to equal <div class="tab-group">inlineText</div>

The above changes should now convert it to: <div class="tab-group">inline \t\t \rtext \n \r \t</div> to equal <div class="tab-group">inline\rtext\t</div>

So I may need update a few of the tests in inferno before I can move this one on through.

trueadm commented 7 years ago

I've added a fix (taken from the Mithril MSX plugin) that seems to work. Even if it is very long winded and much slower – it seems to work in all the test cases.