feat(es/codegen): Compress \t in string literals more (#4131)

This commit is contained in:
Alexander Akait 2022-03-24 00:37:03 +03:00 committed by GitHub
parent b5b803662b
commit 48f3dc8cc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 33 additions and 33 deletions

View File

@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _default = "\nvoid main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n";
var _default = "\nvoid main() {\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n";
exports.default = _default;

File diff suppressed because one or more lines are too long

View File

@ -36,10 +36,10 @@ var sameName4a = {
}
};
var sameName5a = {
get "\t" () {
get " " () {
return "";
},
set "\t" (n){
set " " (n){
var p4 = n;
var p4;
}

View File

@ -319,7 +319,7 @@ var Formatting;
if (StringUtils.IsNullOrEmpty(existingIndentation)) return "";
var totalIndent = 0;
StringUtils.foreach(existingIndentation, function(c) {
if (c == "\t") totalIndent += tabSize;
if (c == " ") totalIndent += tabSize;
else totalIndent++;
});
totalIndent += level * indentSize;
@ -330,7 +330,7 @@ var Formatting;
return this.GetIndentString(existingIndentation, totalIndentSize, tabSize, convertTabsToSpaces);
};
_proto.GetIndentString = function GetIndentString(prefix, totalIndentSize, tabSize, convertTabsToSpaces) {
var tabString = convertTabsToSpaces ? StringUtils.create(" ", tabSize) : "\t";
var tabString = convertTabsToSpaces ? StringUtils.create(" ", tabSize) : " ";
var text = "";
if (!StringUtils.IsNullOrEmpty(prefix)) text += prefix;
var pos = 0;
@ -501,7 +501,7 @@ var Formatting;
var line = this.snapshot.GetLineFromPosition(offset);
var lineText = line.getText();
var index = 0;
while(index < lineText.length && (lineText.charAt(index) == " " || lineText.charAt(index) == "\t")){
while(index < lineText.length && (lineText.charAt(index) == " " || lineText.charAt(index) == " ")){
++index;
}
return lineText.substr(0, index);
@ -550,7 +550,7 @@ var Formatting;
var indentSize = 0;
for(var i = 0; i < text.length; i++){
var c = text.charAt(i);
if (c == "\t") indentSize = indentSize + editorOptions.TabSize - indentSize % editorOptions.TabSize;
if (c == " ") indentSize = indentSize + editorOptions.TabSize - indentSize % editorOptions.TabSize;
else if (c == " ") indentSize += 1;
else {
if (includeNonIndentChars) indentSize += 1;

View File

@ -128,12 +128,12 @@ import * as swcHelpers from "@swc/helpers";
if (StringUtils.IsNullOrEmpty(existingIndentation)) return "";
var totalIndent = 0;
return (StringUtils.foreach(existingIndentation, function(c) {
"\t" == c ? totalIndent += tabSize : totalIndent++;
" " == c ? totalIndent += tabSize : totalIndent++;
}), (totalIndent += level * indentSize) < 0) ? "" : this.GetIndentString(null, totalIndent, tabSize, convertTabsToSpaces);
}
return this.GetIndentString(existingIndentation, level * indentSize, tabSize, convertTabsToSpaces);
}, _proto.GetIndentString = function(prefix, totalIndentSize, tabSize, convertTabsToSpaces) {
var tabString = convertTabsToSpaces ? StringUtils.create(" ", tabSize) : "\t", text = "";
var tabString = convertTabsToSpaces ? StringUtils.create(" ", tabSize) : " ", text = "";
StringUtils.IsNullOrEmpty(prefix) || (text += prefix);
for(var pos = 0; pos <= totalIndentSize - tabSize;)text += tabString, pos += tabSize;
for(; pos < totalIndentSize;)text += " ", pos++;
@ -196,7 +196,7 @@ import * as swcHelpers from "@swc/helpers";
}, _proto.GetLineIndentationForOffset = function(offset) {
var indentationEdit;
if (null != (indentationEdit = this.indentationBag.FindIndent(offset))) return indentationEdit.Indentation();
for(var lineText = this.snapshot.GetLineFromPosition(offset).getText(), index = 0; index < lineText.length && (" " == lineText.charAt(index) || "\t" == lineText.charAt(index));)++index;
for(var lineText = this.snapshot.GetLineFromPosition(offset).getText(), index = 0; index < lineText.length && (" " == lineText.charAt(index) || " " == lineText.charAt(index));)++index;
return lineText.substr(0, index);
}, _proto.RegisterIndentation = function(indent, sameLineIndent) {
var indentationInfo = null;
@ -230,7 +230,7 @@ import * as swcHelpers from "@swc/helpers";
}, Indenter.GetIndentSizeFromText = function(text, editorOptions, includeNonIndentChars) {
for(var indentSize = 0, i = 0; i < text.length; i++){
var c = text.charAt(i);
if ("\t" == c) indentSize = indentSize + editorOptions.TabSize - indentSize % editorOptions.TabSize;
if (" " == c) indentSize = indentSize + editorOptions.TabSize - indentSize % editorOptions.TabSize;
else if (" " == c) indentSize += 1;
else if (includeNonIndentChars) indentSize += 1;
else break;

View File

@ -1,2 +1,2 @@
//@target: es6
"\t\n\v\f\r";
" \n\v\f\r";

View File

@ -1,3 +1,3 @@
//@target: es6
// <TAB>, <VT>, <FF>, <SP>, <NBSP>, <BOM>
"\t\v\f \xa0\uFEFF";
" \v\f \xa0\uFEFF";

View File

@ -1 +1 @@
"\t\v\f \xa0\uFEFF";
" \v\f \xa0\uFEFF";

View File

@ -1,2 +1,2 @@
// <TAB>, <VT>, <FF>, <SP>, <NBSP>, <BOM>
"\t\v\f \xa0\uFEFF";
" \v\f \xa0\uFEFF";

View File

@ -1 +1 @@
"\t\v\f \xa0\uFEFF";
" \v\f \xa0\uFEFF";

View File

@ -3308,7 +3308,7 @@ fn get_quoted_utf16(v: &str, target: EsVersion) -> String {
'\n' => buf.push_str("\\n"),
'\r' => buf.push_str("\\r"),
'\u{000b}' => buf.push_str("\\v"),
'\t' => buf.push_str("\\t"),
'\t' => buf.push('\t'),
'\\' => {
let next = iter.peek();

View File

@ -571,7 +571,7 @@ fn test_get_quoted_utf16() {
);
es2020("\n", "\"\\n\"");
es2020("\t", "\"\\t\"");
es2020("\t", "\"\t\"");
es2020("'string'", "\"'string'\"");
@ -678,7 +678,7 @@ fn issue3617() {
module.exports = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002' +
'\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF' + '\u{a0}';";
let expected = r#"// a string of all valid unicode whitespaces
module.exports = "\t\n\v\f\r \xa0\u1680\u2000\u2001\u2002" + "\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF" + "\xa0";"#;
module.exports = " \n\v\f\r \xa0\u1680\u2000\u2001\u2002" + "\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF" + "\xa0";"#;
let out = parse_then_emit(from, Default::default(), Syntax::default(), EsVersion::Es5);

View File

@ -1,3 +1,3 @@
const string1="test";const string2="test";const string3='te"st';const string4="te'st";const string5="test\ntest\ntest";const string6=`Yet another string primitive`;const string7="This is a very long string which needs to wrap across multiple lines because otherwise my code is unreadable.";const string8="\u4E2D\u6587 espa\xf1ol English \u0939\u093F\u0928\u094D\u0926\u0940 \u0627\u0644\u0639\u0631\u0628\u064A\u0629 portugu\xeas \u09AC\u09BE\u0982\u09B2\u09BE \u0440\u0443\u0441\u0441\u043A\u0438\u0439 \u65E5\u672C\u8A9E \u0A2A\u0A70\u0A1C\u0A3E\u0A2C\u0A40 \uD55C\uAD6D\uC5B4 \u0BA4\u0BAE\u0BBF\u0BB4\u0BCD";const string9=``;const string10=`xx\`x`;const string11=`${foo+2}`;const string12=` foo ${bar+`baz ${qux}`}`;const string13=String.raw`foo`;const string14=foo`bar`;const string15=`foo
bar
ↂωↂ`;const string16=`\``;const string17=`${4+4} equals 4 + 4`;const string18=`This is ${undefined}`;const string19=`This is ${NaN}`;const string20=`This is ${null}`;const string21=`This is ${Infinity}`;const string22="This is ${1/0}";const string23="This is ${1/0}";const string24="This is ${NaN}";const string25="This is ${null}";const string26=`This is ${1/0}`;const string27=`This is ${0/0}`;const string28="This is ${0/0}";const string29="This is ${0/0}";const string30=`${4**11}`;const string31=`${4**12}`;const string32=`${4**14}`;const string33="";const string34="\b";const string35="\f";const string36="\t";const string37="\v";const string38="\n";const string39="\\n";const string40="\\";const string41='\\"';const string42="'\"";const string43="\\\\";const string44="\0";const string45="\0!";const string46="\x001";const string47="\\0";const string48="\\0!";const string49="\x07";const string50="\x07!";const string51="\x071";const string52="\x07";const string53="\\7";const string54="\\7!";const string55="\\01";const string56="\x10";const string57="\\x10";const string58="\x1b";const string59="\\x1B";const string60="\uABCD";const string61="\uABCD";const string62="U000123AB";const string63="\u{123AB}";const string64="\ud808\udfab";const string65="\ud808";const string66="\ud808X";const string67="\udfab";const string68="\udfabX";const string69="\x80";const string70="\xff";const string71="\xf0\x9f\x8d\x95";const string72="\ud801\udc02\udc03\ud804";const string73="\u03C0";const ="\u{1F408}";const 貓abc="\u{1F408}";const abc貓="\u{1F408}";const string74="\u2028";const string75="\u2029";const string76="\uFEFF";const string77="\x10";const string78=" ";const string79=" ";const string80="2";const string81="\x16";const string82="\x06";const string83="\0a";const string84='"test"test"test';const string85="\"test'test'test";const string86='"test"test"test';const string87="'test'test'test";const string88="\u{1F604}";const string89=new RegExp("\r").test("\r");const string90=new RegExp(" ").test(" ");const string91=new RegExp("\x1b").test("["+"\x1b"+"]");const string92=new RegExp("\\x1b").test("\x1b");const string93=new RegExp("\x1b").test("\x1b");const string94="\uD7FF";const string95="\uD7FB";const string96=sql`'#ERROR'`;const string97="\xa0";const string98="\ud83d\ude00";const string99="\ud83d@\ude00";const string100="a";const string101="\u2028"
ↂωↂ`;const string16=`\``;const string17=`${4+4} equals 4 + 4`;const string18=`This is ${undefined}`;const string19=`This is ${NaN}`;const string20=`This is ${null}`;const string21=`This is ${Infinity}`;const string22="This is ${1/0}";const string23="This is ${1/0}";const string24="This is ${NaN}";const string25="This is ${null}";const string26=`This is ${1/0}`;const string27=`This is ${0/0}`;const string28="This is ${0/0}";const string29="This is ${0/0}";const string30=`${4**11}`;const string31=`${4**12}`;const string32=`${4**14}`;const string33="";const string34="\b";const string35="\f";const string36=" ";const string37="\v";const string38="\n";const string39="\\n";const string40="\\";const string41='\\"';const string42="'\"";const string43="\\\\";const string44="\0";const string45="\0!";const string46="\x001";const string47="\\0";const string48="\\0!";const string49="\x07";const string50="\x07!";const string51="\x071";const string52="\x07";const string53="\\7";const string54="\\7!";const string55="\\01";const string56="\x10";const string57="\\x10";const string58="\x1b";const string59="\\x1B";const string60="\uABCD";const string61="\uABCD";const string62="U000123AB";const string63="\u{123AB}";const string64="\ud808\udfab";const string65="\ud808";const string66="\ud808X";const string67="\udfab";const string68="\udfabX";const string69="\x80";const string70="\xff";const string71="\xf0\x9f\x8d\x95";const string72="\ud801\udc02\udc03\ud804";const string73="\u03C0";const ="\u{1F408}";const 貓abc="\u{1F408}";const abc貓="\u{1F408}";const string74="\u2028";const string75="\u2029";const string76="\uFEFF";const string77="\x10";const string78=" ";const string79=" ";const string80="2";const string81="\x16";const string82="\x06";const string83="\0a";const string84='"test"test"test';const string85="\"test'test'test";const string86='"test"test"test';const string87="'test'test'test";const string88="\u{1F604}";const string89=new RegExp("\r").test("\r");const string90=new RegExp(" ").test(" ");const string91=new RegExp("\x1b").test("["+"\x1b"+"]");const string92=new RegExp("\\x1b").test("\x1b");const string93=new RegExp("\x1b").test("\x1b");const string94="\uD7FF";const string95="\uD7FB";const string96=sql`'#ERROR'`;const string97="\xa0";const string98="\ud83d\ude00";const string99="\ud83d@\ude00";const string100="a";const string101="\u2028"

View File

@ -1 +1 @@
"\0\x01\x02\x03\x04\x05\x06\x07\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe"+a
"\0\x01\x02\x03\x04\x05\x06\x07\b \n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe"+a

View File

@ -1 +1 @@
"\n\r\t\v\b\f\\'\"\0"
"\n\r \v\b\f\\'\"\0"

View File

@ -1 +1 @@
"\0\x01\x02\x03\x04\x05\x06\x07\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe" + a;
"\0\x01\x02\x03\x04\x05\x06\x07\b \n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe" + a;

View File

@ -1 +1 @@
"\n\r\t\v\b\f\\'\"\0";
"\n\r \v\b\f\\'\"\0";

View File

@ -1 +1 @@
("\t");
(" ");

View File

@ -5023,7 +5023,7 @@
};
},
88443: function(module) {
module.exports = "\t\n\v\f\r \xa0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF";
module.exports = " \n\v\f\r \xa0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF";
},
23895: function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
"use strict";

View File

@ -2589,7 +2589,7 @@
(event = {
type: 'tag',
tagType: 'skip'
}).attributes = parseAttributes(match[1]), event.attributes.hasOwnProperty('SKIPPED-SEGMENTS') && (event.attributes['SKIPPED-SEGMENTS'] = parseInt(event.attributes['SKIPPED-SEGMENTS'], 10)), event.attributes.hasOwnProperty('RECENTLY-REMOVED-DATERANGES') && (event.attributes['RECENTLY-REMOVED-DATERANGES'] = event.attributes['RECENTLY-REMOVED-DATERANGES'].split("\t")), _this2.trigger('data', event);
}).attributes = parseAttributes(match[1]), event.attributes.hasOwnProperty('SKIPPED-SEGMENTS') && (event.attributes['SKIPPED-SEGMENTS'] = parseInt(event.attributes['SKIPPED-SEGMENTS'], 10)), event.attributes.hasOwnProperty('RECENTLY-REMOVED-DATERANGES') && (event.attributes['RECENTLY-REMOVED-DATERANGES'] = event.attributes['RECENTLY-REMOVED-DATERANGES'].split(" ")), _this2.trigger('data', event);
return;
}
if ((match = /^#EXT-X-PART:(.*)$/.exec(newLine)) && match[1]) {

View File

@ -1229,7 +1229,7 @@ var load77 = __swcpack_require__.bind(void 0, function(module, exports) {
});
});
var load78 = __swcpack_require__.bind(void 0, function(module, exports) {
module.exports = "\t\n\v\f\r \xa0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF";
module.exports = " \n\v\f\r \xa0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF";
});
var load79 = __swcpack_require__.bind(void 0, function(module, exports) {
var $export = load20();