Commit 56254974 authored by chenwilliam's avatar chenwilliam Committed by Commit bot

DevTools: don't cherrypick Common files for Gonzales

Previous, Gonzales was cherrypicking files from Common module for the
TextRange class which was used as a struct.

BUG=none

Review-Url: https://codereview.chromium.org/2625163002
Cr-Commit-Position: refs/heads/master@{#443148}
parent 6c75f8a3
...@@ -7,6 +7,6 @@ front_end/cm_modes/* ...@@ -7,6 +7,6 @@ front_end/cm_modes/*
front_end/cm_web_modes/* front_end/cm_web_modes/*
front_end/diff/diff_match_patch.js front_end/diff/diff_match_patch.js
front_end/formatter_worker/acorn/acorn.js front_end/formatter_worker/acorn/acorn.js
front_end/gonzales/* front_end/gonzales/gonzales-scss.js
front_end/terminal/xterm.js/** front_end/terminal/xterm.js/**
front_end/protocol_externs.js front_end/protocol_externs.js
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
"scripts": [ "scripts": [
"../cm_web_modes/css.js", "../cm_web_modes/css.js",
"../cm_web_modes/xml.js", "../cm_web_modes/xml.js",
"../common/Text.js",
"../common/TextRange.js",
"ESTreeWalker.js", "ESTreeWalker.js",
"FormatterWorker.js", "FormatterWorker.js",
"acorn/acorn.js", "acorn/acorn.js",
......
...@@ -3,33 +3,25 @@ ...@@ -3,33 +3,25 @@
// found in the LICENSE file. // found in the LICENSE file.
/** /**
* @constructor
* @implements {FormatterWorker.FormatterWorkerContentParser} * @implements {FormatterWorker.FormatterWorkerContentParser}
* @unrestricted
*/ */
Gonzales.SCSSParser = function() Gonzales.SCSSParser = class {
{
}
Gonzales.SCSSParser.prototype = {
/** /**
* @override * @override
* @param {string} content * @param {string} content
* @return {!Array<!Gonzales.SCSSParser.Rule>} * @return {!Array<!Gonzales.SCSSParser.Rule>}
*/ */
parse: function(content) parse(content) {
{
var ast = null; var ast = null;
try { try {
ast = gonzales.parse(content, {syntax: "scss"}); ast = gonzales.parse(content, {syntax: 'scss'});
} catch (e) { } catch (e) {
return []; return [];
} }
/** @type {!{properties: !Array<!Gonzales.Node>, node: !Gonzales.Node}} */ /** @type {!{properties: !Array<!Gonzales.Node>, node: !Gonzales.Node}} */
var rootBlock = { var rootBlock = {properties: [], node: ast};
properties: [],
node: ast
};
/** @type {!Array<!{properties: !Array<!Gonzales.Node>, node: !Gonzales.Node}>} */ /** @type {!Array<!{properties: !Array<!Gonzales.Node>, node: !Gonzales.Node}>} */
var blocks = [rootBlock]; var blocks = [rootBlock];
ast.selectors = []; ast.selectors = [];
...@@ -39,123 +31,118 @@ Gonzales.SCSSParser.prototype = { ...@@ -39,123 +31,118 @@ Gonzales.SCSSParser.prototype = {
for (var block of blocks) for (var block of blocks)
this._handleBlock(block, rules); this._handleBlock(block, rules);
return rules; return rules;
}, }
/** /**
* @param {!{node: !Gonzales.Node, properties: !Array<!Gonzales.Node>}} block * @param {!{node: !Gonzales.Node, properties: !Array<!Gonzales.Node>}} block
* @param {!Array<!Gonzales.SCSSParser.Rule>} output * @param {!Array<!Gonzales.SCSSParser.Rule>} output
*/ */
_handleBlock: function(block, output) _handleBlock(block, output) {
{
var selectors = block.node.selectors.map(Gonzales.SCSSParser.rangeFromNode); var selectors = block.node.selectors.map(Gonzales.SCSSParser.rangeFromNode);
var properties = []; var properties = [];
var styleRange = Gonzales.SCSSParser.rangeFromNode(block.node); var styleRange = Gonzales.SCSSParser.rangeFromNode(block.node);
styleRange.startColumn += 1; styleRange.startColumn += 1;
styleRange.endColumn -= 1; styleRange.endColumn -= 1;
for (var node of block.properties) { for (var node of block.properties) {
if (node.type === "declaration") if (node.type === 'declaration')
this._handleDeclaration(node, properties); this._handleDeclaration(node, properties);
else if (node.type === "include") else if (node.type === 'include')
this._handleInclude(node, properties); this._handleInclude(node, properties);
else if (node.type === "multilineComment" && node.start.line === node.end.line) else if (node.type === 'multilineComment' && node.start.line === node.end.line)
this._handleComment(node, properties); this._handleComment(node, properties);
} }
if (!selectors.length && !properties.length) if (!selectors.length && !properties.length)
return; return;
var rule = new Gonzales.SCSSParser.Rule(selectors, properties, styleRange); var rule = new Gonzales.SCSSParser.Rule(selectors, properties, styleRange);
output.push(rule); output.push(rule);
}, }
/** /**
* @param {!Gonzales.Node} node * @param {!Gonzales.Node} node
* @param {!Array<!Gonzales.SCSSParser.Property>} output * @param {!Array<!Gonzales.SCSSParser.Property>} output
*/ */
_handleDeclaration: function(node, output) _handleDeclaration(node, output) {
{ var propertyNode = node.content.find(node => node.type === 'property');
var propertyNode = node.content.find(node => node.type === "property"); var valueNode = node.content.find(node => node.type === 'value');
var valueNode = node.content.find(node => node.type === "value");
if (!propertyNode || !valueNode) if (!propertyNode || !valueNode)
return; return;
var nameRange = Gonzales.SCSSParser.rangeFromNode(propertyNode); var nameRange = Gonzales.SCSSParser.rangeFromNode(propertyNode);
var valueRange = Gonzales.SCSSParser.rangeFromNode(valueNode); var valueRange = Gonzales.SCSSParser.rangeFromNode(valueNode);
var range = /** @type {!Common.TextRange} */(node.declarationRange); var range = /** @type {!Gonzales.TextRange} */ (node.declarationRange);
var property = new Gonzales.SCSSParser.Property(range, nameRange, valueRange, false); var property = new Gonzales.SCSSParser.Property(range, nameRange, valueRange, false);
output.push(property); output.push(property);
}, }
/** /**
* @param {!Gonzales.Node} node * @param {!Gonzales.Node} node
* @param {!Array<!Gonzales.SCSSParser.Property>} output * @param {!Array<!Gonzales.SCSSParser.Property>} output
*/ */
_handleInclude: function(node, output) _handleInclude(node, output) {
{ var mixinName = node.content.find(node => node.type === 'ident');
var mixinName = node.content.find(node => node.type === "ident");
if (!mixinName) if (!mixinName)
return; return;
var nameRange = Gonzales.SCSSParser.rangeFromNode(mixinName); var nameRange = Gonzales.SCSSParser.rangeFromNode(mixinName);
var mixinArguments = node.content.find(node => node.type === "arguments"); var mixinArguments = node.content.find(node => node.type === 'arguments');
if (!mixinArguments) if (!mixinArguments)
return; return;
var parameters = mixinArguments.content.filter(node => node.type !== "delimiter" && node.type !== "space"); var parameters = mixinArguments.content.filter(node => node.type !== 'delimiter' && node.type !== 'space');
for (var parameter of parameters) { for (var parameter of parameters) {
var range = Gonzales.SCSSParser.rangeFromNode(node); var range = Gonzales.SCSSParser.rangeFromNode(node);
var valueRange = Gonzales.SCSSParser.rangeFromNode(parameter); var valueRange = Gonzales.SCSSParser.rangeFromNode(parameter);
var property = new Gonzales.SCSSParser.Property(range, nameRange, valueRange, false); var property = new Gonzales.SCSSParser.Property(range, nameRange, valueRange, false);
output.push(property); output.push(property);
} }
}, }
/** /**
* @param {!Gonzales.Node} node * @param {!Gonzales.Node} node
* @param {!Array<!Gonzales.SCSSParser.Property>} output * @param {!Array<!Gonzales.SCSSParser.Property>} output
*/ */
_handleComment: function(node, output) _handleComment(node, output) {
{
if (node.start.line !== node.end.line) if (node.start.line !== node.end.line)
return; return;
var innerText = /** @type {string} */(node.content); var innerText = /** @type {string} */ (node.content);
var innerResult = this.parse(innerText); var innerResult = this.parse(innerText);
if (innerResult.length !== 1 || innerResult[0].properties.length !== 1) if (innerResult.length !== 1 || innerResult[0].properties.length !== 1)
return; return;
var property = innerResult[0].properties[0]; var property = innerResult[0].properties[0];
var disabledProperty = property.rebaseInsideOneLineComment(node); var disabledProperty = property.rebaseInsideOneLineComment(node);
output.push(disabledProperty); output.push(disabledProperty);
}, }
} };
/** /**
* @param {!Gonzales.Node} node * @param {!Gonzales.Node} node
* @return {!Common.TextRange} * @return {!Gonzales.TextRange}
*/ */
Gonzales.SCSSParser.rangeFromNode = function(node) Gonzales.SCSSParser.rangeFromNode = function(node) {
{ return new Gonzales.TextRange(node.start.line - 1, node.start.column - 1, node.end.line - 1, node.end.column);
return new Common.TextRange(node.start.line - 1, node.start.column - 1, node.end.line - 1, node.end.column); };
}
/** /**
* @constructor * @unrestricted
* @param {!Common.TextRange} range */
* @param {!Common.TextRange} nameRange Gonzales.SCSSParser.Property = class {
* @param {!Common.TextRange} valueRange /**
* @param {!Gonzales.TextRange} range
* @param {!Gonzales.TextRange} nameRange
* @param {!Gonzales.TextRange} valueRange
* @param {boolean} disabled * @param {boolean} disabled
*/ */
Gonzales.SCSSParser.Property = function(range, nameRange, valueRange, disabled) constructor(range, nameRange, valueRange, disabled) {
{
this.range = range; this.range = range;
this.name = nameRange; this.name = nameRange;
this.value = valueRange; this.value = valueRange;
this.disabled = disabled; this.disabled = disabled;
} }
Gonzales.SCSSParser.Property.prototype = {
/** /**
* @param {!Gonzales.Node} commentNode * @param {!Gonzales.Node} commentNode
* @return {!Gonzales.SCSSParser.Property} * @return {!Gonzales.SCSSParser.Property}
*/ */
rebaseInsideOneLineComment: function(commentNode) rebaseInsideOneLineComment(commentNode) {
{
var lineOffset = commentNode.start.line - 1; var lineOffset = commentNode.start.line - 1;
// Account for the "/*". // Account for the "/*".
var columnOffset = commentNode.start.column - 1 + 2; var columnOffset = commentNode.start.column - 1 + 2;
...@@ -165,66 +152,68 @@ Gonzales.SCSSParser.Property.prototype = { ...@@ -165,66 +152,68 @@ Gonzales.SCSSParser.Property.prototype = {
return new Gonzales.SCSSParser.Property(range, name, value, true); return new Gonzales.SCSSParser.Property(range, name, value, true);
/** /**
* @param {!Common.TextRange} range * @param {!Gonzales.TextRange} range
* @param {number} lineOffset * @param {number} lineOffset
* @param {number} columnOffset * @param {number} columnOffset
* @return {!Common.TextRange} * @return {!Gonzales.TextRange}
*/ */
function rebaseRange(range, lineOffset, columnOffset) function rebaseRange(range, lineOffset, columnOffset) {
{ return new Gonzales.TextRange(
return new Common.TextRange(range.startLine + lineOffset, range.startColumn + columnOffset, range.endLine + lineOffset, range.endColumn + columnOffset); range.startLine + lineOffset, range.startColumn + columnOffset, range.endLine + lineOffset,
range.endColumn + columnOffset);
} }
} }
} };
/** /**
* @constructor * @unrestricted
* @param {!Array<!Common.TextRange>} selectors */
Gonzales.SCSSParser.Rule = class {
/**
* @param {!Array<!Gonzales.TextRange>} selectors
* @param {!Array<!Gonzales.SCSSParser.Property>} properties * @param {!Array<!Gonzales.SCSSParser.Property>} properties
* @param {!Common.TextRange} styleRange * @param {!Gonzales.TextRange} styleRange
*/ */
Gonzales.SCSSParser.Rule = function(selectors, properties, styleRange) constructor(selectors, properties, styleRange) {
{
this.selectors = selectors; this.selectors = selectors;
this.properties = properties; this.properties = properties;
this.styleRange = styleRange; this.styleRange = styleRange;
} }
};
/** /**
* @param {!Gonzales.Node} node * @param {!Gonzales.Node} node
* @param {!Array<{node: !Gonzales.Node, properties: !Array<!Gonzales.Node>}>} blocks * @param {!Array<{node: !Gonzales.Node, properties: !Array<!Gonzales.Node>}>} blocks
* @param {!{node: !Gonzales.Node, properties: !Array<!Gonzales.Node>}} lastBlock * @param {!{node: !Gonzales.Node, properties: !Array<!Gonzales.Node>}} lastBlock
*/ */
Gonzales.SCSSParser.extractNodes = function(node, blocks, lastBlock) Gonzales.SCSSParser.extractNodes = function(node, blocks, lastBlock) {
{
if (!Array.isArray(node.content)) if (!Array.isArray(node.content))
return; return;
if (node.type === "block") { if (node.type === 'block') {
lastBlock = { lastBlock = {node: node, properties: []};
node: node,
properties: []
};
blocks.push(lastBlock); blocks.push(lastBlock);
} }
var lastDeclaration = null; var lastDeclaration = null;
var selectors = []; var selectors = [];
for (var i = 0; i < node.content.length; ++i) { for (var i = 0; i < node.content.length; ++i) {
var child = node.content[i]; var child = node.content[i];
if (child.type === "declarationDelimiter" && lastDeclaration) { if (child.type === 'declarationDelimiter' && lastDeclaration) {
lastDeclaration.declarationRange.endLine = child.end.line - 1; lastDeclaration.declarationRange.endLine = child.end.line - 1;
lastDeclaration.declarationRange.endColumn = child.end.column; lastDeclaration.declarationRange.endColumn = child.end.column;
lastDeclaration = null; lastDeclaration = null;
} else if (child.type === "selector") { } else if (child.type === 'selector') {
selectors.push(child); selectors.push(child);
} else if (child.type === "block") { } else if (child.type === 'block') {
child.selectors = selectors; child.selectors = selectors;
selectors = []; selectors = [];
} }
if (child.type === "include" || child.type === "declaration" || child.type === "multilineComment") if (child.type === 'include' || child.type === 'declaration' || child.type === 'multilineComment')
lastBlock.properties.push(child); lastBlock.properties.push(child);
if (child.type === "declaration") { if (child.type === 'declaration') {
lastDeclaration = child; lastDeclaration = child;
lastDeclaration.declarationRange = Common.TextRange.createFromLocation(child.start.line - 1, child.start.column - 1); const line = child.start.line - 1;
const column = child.start.column - 1;
lastDeclaration.declarationRange = new Gonzales.TextRange(line, column, line, column);
} }
Gonzales.SCSSParser.extractNodes(child, blocks, lastBlock); Gonzales.SCSSParser.extractNodes(child, blocks, lastBlock);
} }
...@@ -232,4 +221,22 @@ Gonzales.SCSSParser.extractNodes = function(node, blocks, lastBlock) ...@@ -232,4 +221,22 @@ Gonzales.SCSSParser.extractNodes = function(node, blocks, lastBlock)
lastDeclaration.declarationRange.endLine = node.end.line - 1; lastDeclaration.declarationRange.endLine = node.end.line - 1;
lastDeclaration.declarationRange.endColumn = node.end.column - 1; lastDeclaration.declarationRange.endColumn = node.end.column - 1;
} }
} };
/**
* @unrestricted
*/
Gonzales.TextRange = class {
/**
* @param {number} startLine
* @param {number} startColumn
* @param {number} endLine
* @param {number} endColumn
*/
constructor(startLine, startColumn, endLine, endColumn) {
this.startLine = startLine;
this.startColumn = startColumn;
this.endLine = endLine;
this.endColumn = endColumn;
}
};
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment