From f3d1138d7325a3390ac5a93249952750982b648b Mon Sep 17 00:00:00 2001 From: Albin Zeng Date: Tue, 25 Sep 2018 10:58:11 +0800 Subject: [PATCH 1/2] fix: current alias for identifier in stringify process. --- package.json | 2 +- src/stringify.js | 18 +++--------------- test/main.test.js | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 1fe3d7c..1934183 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "./dist/parser/sqlParser.js", "scripts": { "build": "jison -m js ./src/sqlParser.jison -o ./dist/parser/sqlParser.js && npm run build-concat", - "build-concat": "concat -o ./dist/parser/sqlParser.js ./dist/parser/sqlParser.js src/stringify.js src/suffix.js", + "build-concat": "cat src/stringify.js src/suffix.js >> ./dist/parser/sqlParser.js", "postbuild": "npm run test:build", "test:all": "mocha --require babel-register", "test:build": "mocha 'test/*.test.js'", diff --git a/src/stringify.js b/src/stringify.js index dd15a42..fd1d289 100644 --- a/src/stringify.js +++ b/src/stringify.js @@ -130,11 +130,11 @@ Sql.prototype.travelSelectExpr = function (ast) { this.append(exprList[i]); } else { this.travel(exprList[i]); - if (ast.alias) { - if (ast.hasAs) { + if (exprList[i].alias) { + if (exprList[i].hasAs) { this.appendKeyword('as'); } - this.travel(ast.alias); + this.travel(exprList[i].alias); } } if (i !== exprList.length - 1) { @@ -184,12 +184,6 @@ Sql.prototype.travelFunctionCall = function (ast) { } } this.append(')', true); - if (ast.alias) { - if (ast.hasAs) { - this.appendKeyword('as'); - } - this.travel(ast.alias); - } } Sql.prototype.travelFunctionCallParam = function (ast) { if (ast.distinctOpt) { @@ -249,12 +243,6 @@ Sql.prototype.travelSubQuery = function (ast) { this.append('(', false, true); this.travel(ast.value); this.append(')', true); - if (ast.alias) { - if (ast.hasAs) { - this.appendKeyword('as'); - } - this.travel(ast.alias); - } } Sql.prototype.travelIdentifierExpr = function (ast) { this.append('{'); diff --git a/test/main.test.js b/test/main.test.js index 77a6545..b4114ba 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -357,7 +357,7 @@ describe('select grammar support', function () { }); it ('recognoce alias for sql-function calls in stringify function.', function () { - testParser('SELECT COUNT(*) AS total FROM b'); + testParser('SELECT COUNT(*) AS total, a b, b as c, c/2 d, d & e an FROM b'); }); }); From a7be5ae02276c04dca222decfb25405eaa789702 Mon Sep 17 00:00:00 2001 From: Albin Zeng Date: Tue, 25 Sep 2018 11:10:33 +0800 Subject: [PATCH 2/2] fix: .travis.yml test. --- .travis.yml | 2 +- package.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 43a129c..4ba6f27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,5 +12,5 @@ node_js: - "v8.11.3" - "v10.7.0" scripts: { - "test": "make test" + "test": "npm run test:build" } diff --git a/package.json b/package.json index 1934183..a2013ec 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,10 @@ "build": "jison -m js ./src/sqlParser.jison -o ./dist/parser/sqlParser.js && npm run build-concat", "build-concat": "cat src/stringify.js src/suffix.js >> ./dist/parser/sqlParser.js", "postbuild": "npm run test:build", + "test": "npm run build", "test:all": "mocha --require babel-register", - "test:build": "mocha 'test/*.test.js'", - "test:benchmark": "mocha test/benchmark.js" + "test:build": "mocha --require babel-register 'test/*.test.js'", + "test:benchmark": "mocha --require babel-register test/benchmark.js" }, "repository": { "type": "git",