This commit is contained in:
Jun Pataleta
2025-03-06 17:22:17 +08:00
10 changed files with 1938 additions and 1223 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1615,6 +1615,10 @@ TemplatablePattern.prototype.__set_templated_pattern = function() {
if (!this._disabled.handlebars) {
items.push(this.__patterns.handlebars._starting_pattern.source);
}
if (!this._disabled.angular) {
// Handlebars ('{{' and '}}') are also special tokens in Angular)
items.push(this.__patterns.handlebars._starting_pattern.source);
}
if (!this._disabled.erb) {
items.push(this.__patterns.erb._starting_pattern.source);
}
@@ -2040,7 +2044,7 @@ Beautifier.prototype.beautify = function() {
type: ''
};
var last_tag_token = new TagOpenParserToken();
var last_tag_token = new TagOpenParserToken(this._options);
var printer = new Printer(this._options, baseIndentString);
var tokens = new Tokenizer(source_text, this._options).tokenize();
@@ -2363,7 +2367,7 @@ Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_to
return parser_token;
};
var TagOpenParserToken = function(parent, raw_token) {
var TagOpenParserToken = function(options, parent, raw_token) {
this.parent = parent || null;
this.text = '';
this.type = 'TK_TAG_OPEN';
@@ -2430,13 +2434,14 @@ var TagOpenParserToken = function(parent, raw_token) {
}
// handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
// if they start with # or ^, they are still considered single tags if indenting of handlebars is set to false
this.is_end_tag = this.is_end_tag ||
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
(this.tag_start_char === '{' && (!options.indent_handlebars || this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
}
};
Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
var parser_token = new TagOpenParserToken(this._options, this._tag_stack.get_parser_token(), raw_token);
parser_token.alignment_size = this._options.wrap_attributes_indent_size;
@@ -2903,6 +2908,7 @@ Tokenizer.prototype._get_next_token = function(previous_token, open_token) { //
token = token || this._read_open_handlebars(c, open_token);
token = token || this._read_attribute(c, previous_token, open_token);
token = token || this._read_close(c, open_token);
token = token || this._read_script_and_style(c, previous_token);
token = token || this._read_control_flows(c, open_token);
token = token || this._read_raw_content(c, previous_token, open_token);
token = token || this._read_content_word(c, open_token);
@@ -2988,8 +2994,8 @@ Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
var resulting_string = null;
var token = null;
if (!open_token || open_token.type === TOKEN.CONTROL_FLOW_OPEN) {
if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
if (this._input.peek(2) === '!') {
if ((this._options.templating.includes('angular') || this._options.indent_handlebars) && c === '{' && this._input.peek(1) === '{') {
if (this._options.indent_handlebars && this._input.peek(2) === '!') {
resulting_string = this.__patterns.handlebars_comment.read();
resulting_string = resulting_string || this.__patterns.handlebars.read();
token = this._create_token(TOKEN.COMMENT, resulting_string);
@@ -3005,8 +3011,8 @@ Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
Tokenizer.prototype._read_control_flows = function(c, open_token) {
var resulting_string = '';
var token = null;
// Only check for control flows if angular templating is set AND indenting is set
if (!this._options.templating.includes('angular') || !this._options.indent_handlebars) {
// Only check for control flows if angular templating is set
if (!this._options.templating.includes('angular')) {
return token;
}
@@ -3099,7 +3105,6 @@ Tokenizer.prototype._is_content_unformatted = function(tag_name) {
this._options.unformatted.indexOf(tag_name) !== -1);
};
Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
var resulting_string = '';
if (open_token && open_token.text[0] === '{') {
@@ -3108,16 +3113,7 @@ Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token)
previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
// ^^ empty tag has no content
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
if (tag_name === 'script' || tag_name === 'style') {
// Script and style tags are allowed to have comments wrapping their content
// or just have regular content.
var token = this._read_comment_or_cdata(c);
if (token) {
token.type = TOKEN.TEXT;
return token;
}
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
} else if (this._is_content_unformatted(tag_name)) {
if (this._is_content_unformatted(tag_name)) {
resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
}
@@ -3130,6 +3126,26 @@ Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token)
return null;
};
Tokenizer.prototype._read_script_and_style = function(c, previous_token) { // jshint unused:false
if (previous_token.type === TOKEN.TAG_CLOSE && previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
var tag_name = previous_token.opened.text.substr(1).toLowerCase();
if (tag_name === 'script' || tag_name === 'style') {
// Script and style tags are allowed to have comments wrapping their content
// or just have regular content.
var token = this._read_comment_or_cdata(c);
if (token) {
token.type = TOKEN.TEXT;
return token;
}
var resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
if (resulting_string) {
return this._create_token(TOKEN.TEXT, resulting_string);
}
}
}
return null;
};
Tokenizer.prototype._read_content_word = function(c, open_token) {
var resulting_string = '';
if (this._options.unformatted_content_delimiter) {
@@ -3144,6 +3160,7 @@ Tokenizer.prototype._read_content_word = function(c, open_token) {
if (resulting_string) {
return this._create_token(TOKEN.TEXT, resulting_string);
}
return null;
};
module.exports.Tokenizer = Tokenizer;
@@ -3912,6 +3912,10 @@ TemplatablePattern.prototype.__set_templated_pattern = function() {
if (!this._disabled.handlebars) {
items.push(this.__patterns.handlebars._starting_pattern.source);
}
if (!this._disabled.angular) {
// Handlebars ('{{' and '}}') are also special tokens in Angular)
items.push(this.__patterns.handlebars._starting_pattern.source);
}
if (!this._disabled.erb) {
items.push(this.__patterns.erb._starting_pattern.source);
}
File diff suppressed because one or more lines are too long
+10 -10
View File
@@ -12,7 +12,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/autocomplete</name>
<description>Autocompletion for the CodeMirror code editor.</description>
<version>6.16.0</version>
<version>6.18.6</version>
<license>MIT</license>
<repository>https://github.com/codemirror/autocomplete</repository>
</library>
@@ -20,7 +20,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/commands</name>
<description>Collection of editing commands for the CodeMirror code editor.</description>
<version>6.5.0</version>
<version>6.8.0</version>
<license>MIT</license>
<repository>https://github.com/codemirror/commands</repository>
</library>
@@ -28,7 +28,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/lang-css</name>
<description>CSS language support for the CodeMirror code editor.</description>
<version>6.2.1</version>
<version>6.3.1</version>
<license>MIT</license>
<repository>https://github.com/codemirror/lang-css</repository>
</library>
@@ -44,7 +44,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/lang-javascript</name>
<description>JavaScript language support for the CodeMirror code editor.</description>
<version>6.2.2</version>
<version>6.2.3</version>
<license>MIT</license>
<repository>https://github.com/codemirror/lang-javascript</repository>
</library>
@@ -60,7 +60,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/language</name>
<description>Language support infrastructure for the CodeMirror code editor.</description>
<version>6.10.1</version>
<version>6.10.8</version>
<license>MIT</license>
<repository>https://github.com/codemirror/language</repository>
</library>
@@ -68,7 +68,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/lint</name>
<description>Linting support for the CodeMirror code editor.</description>
<version>6.7.1</version>
<version>6.8.4</version>
<license>MIT</license>
<repository>https://github.com/codemirror/lint</repository>
</library>
@@ -76,7 +76,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/search</name>
<description>Search functionality for the CodeMirror code editor.</description>
<version>6.5.6</version>
<version>6.5.9</version>
<license>MIT</license>
<repository>https://github.com/codemirror/search</repository>
</library>
@@ -84,7 +84,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/state</name>
<description>Editor state data structures for the CodeMirror code editor.</description>
<version>6.4.1</version>
<version>6.5.2</version>
<license>MIT</license>
<repository>https://github.com/codemirror/state</repository>
</library>
@@ -92,7 +92,7 @@
<location>amd/src/codemirror-lazy.js</location>
<name>codemirror/view</name>
<description>DOM view component for the CodeMirror code editor.</description>
<version>6.26.3</version>
<version>6.36.2</version>
<license>MIT</license>
<repository>https://github.com/codemirror/view</repository>
</library>
@@ -100,7 +100,7 @@
<location>amd/src/beautify</location>
<name>js-beautify</name>
<description>Beautifier for javascript.</description>
<version>1.15.1</version>
<version>1.15.3</version>
<license>MIT</license>
<repository>https://github.com/beautifier/js-beautify/</repository>
</library>