Permalink
Browse files

Accept only string as the source input.

Fixes #1069
Closes gh-1353
  • Loading branch information...
ariya committed Oct 30, 2015
1 parent 2e1d81c commit a6f5235ad79ec06a4d8567ac8b8c29fbedbc081f
Showing with 10 additions and 159 deletions.
  1. +3 −3 src/parser.ts
  2. +1 −4 src/scanner.ts
  3. +0 −13 test/fixtures/api/migrated_0000.result.json
  4. +0 −1 test/fixtures/api/migrated_0000.run.js
  5. +0 −14 test/fixtures/api/migrated_0001.result.json
  6. +0 −1 test/fixtures/api/migrated_0001.run.js
  7. +0 −14 test/fixtures/api/migrated_0002.result.json
  8. +0 −1 test/fixtures/api/migrated_0002.run.js
  9. +0 −14 test/fixtures/api/migrated_0003.result.json
  10. +0 −1 test/fixtures/api/migrated_0003.run.js
  11. +0 −13 test/fixtures/api/migrated_0004.result.json
  12. +0 −1 test/fixtures/api/migrated_0004.run.js
  13. +0 −14 test/fixtures/api/migrated_0006.result.json
  14. +0 −1 test/fixtures/api/migrated_0006.run.js
  15. +0 −14 test/fixtures/api/migrated_0007.result.json
  16. +0 −1 test/fixtures/api/migrated_0007.run.js
  17. +0 −6 test/fixtures/api/migrated_0009.result.json
  18. +0 −1 test/fixtures/api/migrated_0009.run.js
  19. +0 −6 test/fixtures/api/migrated_0010.result.json
  20. +0 −1 test/fixtures/api/migrated_0010.run.js
  21. +0 −6 test/fixtures/api/migrated_0011.result.json
  22. +0 −1 test/fixtures/api/migrated_0011.run.js
  23. +0 −6 test/fixtures/api/migrated_0012.result.json
  24. +0 −1 test/fixtures/api/migrated_0012.run.js
  25. +0 −6 test/fixtures/api/migrated_0013.result.json
  26. +0 −1 test/fixtures/api/migrated_0013.run.js
  27. +0 −6 test/fixtures/api/migrated_0015.result.json
  28. +0 −1 test/fixtures/api/migrated_0015.run.js
  29. +0 −6 test/fixtures/api/migrated_0016.result.json
  30. +0 −1 test/fixtures/api/migrated_0016.run.js
  31. 0 test/fixtures/tokenize/empty.js
  32. +1 −0 test/fixtures/tokenize/empty.tokens.json
  33. +4 −0 test/fixtures/tokenize/line_terminators.js
  34. +1 −0 test/fixtures/tokenize/line_terminators.tokens.json
View
@@ -3922,7 +3922,7 @@ function filterTokenLocation(tokens) {
return result;
}
-function initialize(code: any, opt: any, delegate: any): void {
+function initialize(code: string, opt: any, delegate: any): void {
options = {
range: false,
loc: false,
@@ -3989,7 +3989,7 @@ function initialize(code: any, opt: any, delegate: any): void {
}
}
-export function tokenize(code, opt, delegate) {
+export function tokenize(code: string, opt, delegate) {
initialize(code, opt, {});
options.tokens = true;
@@ -4026,7 +4026,7 @@ export function tokenize(code, opt, delegate) {
return tokens;
}
-export function parse(code, opt) {
+export function parse(code: string, opt) {
initialize(code, opt, {});
scanner.start();
View
@@ -44,10 +44,7 @@ export class Scanner {
throwUnexpectedToken: any;
tolerateUnexpectedToken: any;
- constructor(code: any, delegate: any) {
- if (typeof code !== 'string' && !(code instanceof String)) {
- code = String(code);
- }
+ constructor(code: string, delegate: any) {
this.source = code;
this.length = code.length;
this.strict = false;
@@ -1,13 +0,0 @@
-{
- "type": "Program",
- "body": [
- {
- "type": "ExpressionStatement",
- "expression": {
- "type": "Identifier",
- "name": "undefined"
- }
- }
- ],
- "sourceType": "script"
-}
@@ -1 +0,0 @@
-esprima.parse();
@@ -1,14 +0,0 @@
-{
- "type": "Program",
- "body": [
- {
- "type": "ExpressionStatement",
- "expression": {
- "type": "Literal",
- "value": null,
- "raw": "null"
- }
- }
- ],
- "sourceType": "script"
-}
@@ -1 +0,0 @@
-esprima.parse(null);
@@ -1,14 +0,0 @@
-{
- "type": "Program",
- "body": [
- {
- "type": "ExpressionStatement",
- "expression": {
- "type": "Literal",
- "value": 42,
- "raw": "42"
- }
- }
- ],
- "sourceType": "script"
-}
@@ -1 +0,0 @@
-esprima.parse(42);
@@ -1,14 +0,0 @@
-{
- "type": "Program",
- "body": [
- {
- "type": "ExpressionStatement",
- "expression": {
- "type": "Literal",
- "value": true,
- "raw": "true"
- }
- }
- ],
- "sourceType": "script"
-}
@@ -1 +0,0 @@
-esprima.parse(true);
@@ -1,13 +0,0 @@
-{
- "type": "Program",
- "body": [
- {
- "type": "ExpressionStatement",
- "expression": {
- "type": "Identifier",
- "name": "undefined"
- }
- }
- ],
- "sourceType": "script"
-}
@@ -1 +0,0 @@
-esprima.parse(void 0);
@@ -1,14 +0,0 @@
-{
- "type": "Program",
- "body": [
- {
- "type": "ExpressionStatement",
- "expression": {
- "type": "Literal",
- "value": 42,
- "raw": "42"
- }
- }
- ],
- "sourceType": "script"
-}
@@ -1 +0,0 @@
-esprima.parse(new Number(42));
@@ -1,14 +0,0 @@
-{
- "type": "Program",
- "body": [
- {
- "type": "ExpressionStatement",
- "expression": {
- "type": "Literal",
- "value": true,
- "raw": "true"
- }
- }
- ],
- "sourceType": "script"
-}
@@ -1 +0,0 @@
-esprima.parse(new Boolean(true));
@@ -1,6 +0,0 @@
-[
- {
- "type": "Identifier",
- "value": "undefined"
- }
-]
@@ -1 +0,0 @@
-esprima.tokenize();
@@ -1,6 +0,0 @@
-[
- {
- "type": "Null",
- "value": "null"
- }
-]
@@ -1 +0,0 @@
-esprima.tokenize(null);
@@ -1,6 +0,0 @@
-[
- {
- "type": "Numeric",
- "value": "42"
- }
-]
@@ -1 +0,0 @@
-esprima.tokenize(42);
@@ -1,6 +0,0 @@
-[
- {
- "type": "Boolean",
- "value": "true"
- }
-]
@@ -1 +0,0 @@
-esprima.tokenize(true);
@@ -1,6 +0,0 @@
-[
- {
- "type": "Identifier",
- "value": "undefined"
- }
-]
@@ -1 +0,0 @@
-esprima.tokenize(void 0);
@@ -1,6 +0,0 @@
-[
- {
- "type": "Numeric",
- "value": "42"
- }
-]
@@ -1 +0,0 @@
-esprima.tokenize(new Number(42));
@@ -1,6 +0,0 @@
-[
- {
- "type": "Boolean",
- "value": "true"
- }
-]
@@ -1 +0,0 @@
-esprima.tokenize(new Boolean(true));
No changes.
@@ -0,0 +1 @@
+[]
@@ -0,0 +1,4 @@
+
+
+
+
@@ -0,0 +1 @@
+[]

0 comments on commit a6f5235

Please sign in to comment.