Skip to content

Commit

Permalink
refactor: export to single declaration file
Browse files Browse the repository at this point in the history
Also:
- refactor: Can't use `@constructor` jsdoc in this situation, so refactor to class
  • Loading branch information
brettz9 committed May 4, 2022
1 parent 4309e52 commit deae6c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
42 changes: 20 additions & 22 deletions lib/token-translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,30 @@ function convertTemplatePart(tokens, code) {
return token;
}

/**
* Contains logic to translate Acorn tokens into Esprima tokens.
* @param {EnhancedTokTypes} acornTokTypes The Acorn token types.
* @param {string} code The source code Acorn is parsing. This is necessary
* to correct the "value" property of some tokens.
* @constructor
*/
function TokenTranslator(acornTokTypes, code) {
class TokenTranslator {

// token types
this._acornTokTypes = acornTokTypes;
/**
* Contains logic to translate Acorn tokens into Esprima tokens.
* @param {EnhancedTokTypes} acornTokTypes The Acorn token types.
* @param {string} code The source code Acorn is parsing. This is necessary
* to correct the "value" property of some tokens.
*/
constructor(acornTokTypes, code) {

// token buffer for templates
/** @type {(acorn.Token)[]} */
this._tokens = [];
// token types
this._acornTokTypes = acornTokTypes;

// track the last curly brace
this._curlyBrace = null;
// token buffer for templates
/** @type {(acorn.Token)[]} */
this._tokens = [];

// the source code
this._code = code;
// track the last curly brace
this._curlyBrace = null;

}
// the source code
this._code = code;

TokenTranslator.prototype = {
constructor: TokenTranslator,
}

/**
* Translates a single Esprima token to a single Acorn token. This may be
Expand Down Expand Up @@ -233,7 +231,7 @@ TokenTranslator.prototype = {
}

return newToken;
},
}

/**
* Function to call during Acorn's onToken handler.
Expand Down Expand Up @@ -319,7 +317,7 @@ TokenTranslator.prototype = {

tokens.push(this.translate(token, extra));
}
};
}

//------------------------------------------------------------------------------
// Public
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"emitDeclarationOnly": true,
"strict": true,
"target": "es5",
"outDir": "dist"
"outFile": "dist/espree.d.ts"
},
"_preprocess_include": ["espree.js", "lib/**/*.js"],
"_preprocess_exclude": ["node_modules"],
Expand Down

0 comments on commit deae6c6

Please sign in to comment.