This repository was archived by the owner on Mar 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -929,7 +929,7 @@ JsFile.prototype = {
929929 } ,
930930
931931 /**
932- * Temporary fix (I hope, two years and counting :-) for esprima tokenizer
932+ * Temporary fix (I hope, two years and counting :-) for esprima/babylon tokenizer
933933 * (https://github.com/jquery/esprima/issues/317)
934934 * Fixes #83, #180
935935 *
@@ -938,11 +938,14 @@ JsFile.prototype = {
938938 _fixEsprimaIdentifiers : function ( ) {
939939 var _this = this ;
940940
941- this . iterateNodesByType ( [ 'Property' , 'MemberExpression' ] , function ( node ) {
941+ this . iterateNodesByType ( [ 'Property' , 'MethodDefinition' , ' MemberExpression'] , function ( node ) {
942942 switch ( node . type ) {
943943 case 'Property' :
944944 convertKeywordToIdentifierIfRequired ( node . key ) ;
945945 break ;
946+ case 'MethodDefinition' :
947+ convertKeywordToIdentifierIfRequired ( node . key ) ;
948+ break ;
946949 case 'MemberExpression' :
947950 convertKeywordToIdentifierIfRequired ( node . property ) ;
948951 break ;
@@ -951,6 +954,7 @@ JsFile.prototype = {
951954
952955 function convertKeywordToIdentifierIfRequired ( node ) {
953956 var token = _this . getTokenByRangeStart ( node . range [ 0 ] ) ;
957+
954958 if ( token . type === 'Keyword' ) {
955959 token . type = 'Identifier' ;
956960 }
Original file line number Diff line number Diff line change 1+ var fs = require ( 'fs' ) ;
2+
13var expect = require ( 'chai' ) . expect ;
4+ var sinon = require ( 'sinon' ) ;
5+
26var esprima = require ( 'esprima' ) ;
37var babelJscs = require ( 'babel-jscs' ) ;
4- var JsFile = require ( '../../lib/js-file' ) ;
5- var sinon = require ( 'sinon' ) ;
6- var fs = require ( 'fs' ) ;
8+
79var assign = require ( 'lodash' ) . assign ;
10+ var keywords = Object . keys ( require ( 'reserved-words' ) . KEYWORDS [ 6 ] ) ;
11+
12+ var JsFile = require ( '../../lib/js-file' ) ;
813
914describe ( 'js-file' , function ( ) {
1015
@@ -62,6 +67,24 @@ describe('js-file', function() {
6267 } ) ;
6368 } ) ;
6469
70+ it ( 'should affect method definition tokens' , function ( ) {
71+ var str = keywords . map ( function ( token ) {
72+ return token + '() {}' ;
73+ } ) ;
74+
75+ str = 'class test {\n' + str . join ( '\n' ) + '\n}' ;
76+
77+ createJsFile ( str ) . getTokens ( ) . forEach ( function ( token , i ) {
78+
79+ // Exclude first "class"
80+ if ( i === 0 ) {
81+ return ;
82+ }
83+
84+ expect ( token . type ) . to . not . equal ( 'Keyword' ) ;
85+ } ) ;
86+ } ) ;
87+
6588 it ( 'should affect member access tokens' , function ( ) {
6689 var str = 'o.break(); o.export(); o.return(); o.case(); o.for(); o.switch(); o.comment();' +
6790 'o.function(); o.this(); o.continue(); o.if(); o.typeof(); o.default(); o.import();' +
You can’t perform that action at this time.
0 commit comments