Skip to content

Commit a3e6f29

Browse files
authored
Merge pull request #17 from JavaScriptor/fix-as-for-identifier
fix: current alias for identifier in stringify process.
2 parents 91f0bb9 + a7be5ae commit a3e6f29

File tree

4 files changed

+9
-20
lines changed

4 files changed

+9
-20
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ node_js:
1212
- "v8.11.3"
1313
- "v10.7.0"
1414
scripts: {
15-
"test": "make test"
15+
"test": "npm run test:build"
1616
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
"main": "./dist/parser/sqlParser.js",
66
"scripts": {
77
"build": "jison -m js ./src/sqlParser.jison -o ./dist/parser/sqlParser.js && npm run build-concat",
8-
"build-concat": "concat -o ./dist/parser/sqlParser.js ./dist/parser/sqlParser.js src/stringify.js src/suffix.js",
8+
"build-concat": "cat src/stringify.js src/suffix.js >> ./dist/parser/sqlParser.js",
99
"postbuild": "npm run test:build",
10+
"test": "npm run build",
1011
"test:all": "mocha --require babel-register",
11-
"test:build": "mocha 'test/*.test.js'",
12-
"test:benchmark": "mocha test/benchmark.js"
12+
"test:build": "mocha --require babel-register 'test/*.test.js'",
13+
"test:benchmark": "mocha --require babel-register test/benchmark.js"
1314
},
1415
"repository": {
1516
"type": "git",

src/stringify.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ Sql.prototype.travelSelectExpr = function (ast) {
130130
this.append(exprList[i]);
131131
} else {
132132
this.travel(exprList[i]);
133-
if (ast.alias) {
134-
if (ast.hasAs) {
133+
if (exprList[i].alias) {
134+
if (exprList[i].hasAs) {
135135
this.appendKeyword('as');
136136
}
137-
this.travel(ast.alias);
137+
this.travel(exprList[i].alias);
138138
}
139139
}
140140
if (i !== exprList.length - 1) {
@@ -184,12 +184,6 @@ Sql.prototype.travelFunctionCall = function (ast) {
184184
}
185185
}
186186
this.append(')', true);
187-
if (ast.alias) {
188-
if (ast.hasAs) {
189-
this.appendKeyword('as');
190-
}
191-
this.travel(ast.alias);
192-
}
193187
}
194188
Sql.prototype.travelFunctionCallParam = function (ast) {
195189
if (ast.distinctOpt) {
@@ -249,12 +243,6 @@ Sql.prototype.travelSubQuery = function (ast) {
249243
this.append('(', false, true);
250244
this.travel(ast.value);
251245
this.append(')', true);
252-
if (ast.alias) {
253-
if (ast.hasAs) {
254-
this.appendKeyword('as');
255-
}
256-
this.travel(ast.alias);
257-
}
258246
}
259247
Sql.prototype.travelIdentifierExpr = function (ast) {
260248
this.append('{');

test/main.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ describe('select grammar support', function () {
357357
});
358358

359359
it ('recognoce alias for sql-function calls in stringify function.', function () {
360-
testParser('SELECT COUNT(*) AS total FROM b');
360+
testParser('SELECT COUNT(*) AS total, a b, b as c, c/2 d, d & e an FROM b');
361361
});
362362

363363
});

0 commit comments

Comments
 (0)