wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 206 forks source link

Fix #167, #170 (react-native), #151, #152, #146 #169

Closed nippur72 closed 8 years ago

nippur72 commented 8 years ago

This fixes #167.

The problem was --modules defaulting to none from the command line, so that the right side of || was always ignored:

finalOptions.modules = finalOptions.modules || (finalOptions.native ? 'commonjs' : 'none');

Similarly for --react-import-path.

The fix consists in avoiding the default values in optionator dependency, and managing them programmatically.

It's backward compatible when --native is not specified. When specified, it adheres to the specs (requires react-native and switches to commonjs).

nippur72 commented 8 years ago
PierBover commented 8 years ago

Awesome. Any idea when this PR will be merged?

nippur72 commented 8 years ago

This PR now fixes #151 too.

Non breaking space appearing alone in a tag were trimmed out because the internal javascript String.prototype.trim() also trims non breaking spaces.

I fixed it by writing a custom trim function that I use in place of the old one:

function trimHtmlText(text) {
    return text.replace(/^[ \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+|[ \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+$/g, '');
}
nippur72 commented 8 years ago

This PR now fixes #152 too, checking that the only valid attributes for <rt-virtual> are rt-if, rt-scope, rt-repeat.

nippur72 commented 8 years ago

This PR now fixes #171 too, checking that rt-repeat does not appear in a root node.

nippur72 commented 8 years ago

This PR now implements #146 too, introducing the --normalize-html-whitespace CLI option.

When the option is turned on (default is off), all HTML text is passed thru normalize-html-whitespace, removing all repeating whitespaces and saving bytes on the JavaScript output.

Often the number of React.createElement() calls is reduced too.

Whitespace removal is applied on all tags except <pre> and <textarea> or when the special rt-pre attribute is specified.

nippur72 commented 8 years ago

Thank you for merging :smile:

The following issues related to this PR can be closed: #144, #157, #168.

These issues instead refer to other already merged PRs and can be closed too: #101, #111, #117.