@@ -81,25 +81,33 @@ define(function (require, exports, module) {
8181 return ( / \S / . test ( text ) ) ;
8282 }
8383
84+ /**
85+ * @private
86+ * Returns state of a token
87+ * @param {{editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} } ctx
88+ * @return {{tokenize:function, state:string, stateArg:string, context:Object} }
89+ */
90+ function _getContextState ( ctx ) {
91+ var state = ctx . token . state . localState || ctx . token . state ;
92+ if ( ! state . context && ctx . token . state . html . localState ) {
93+ state = ctx . token . state . html . localState ;
94+ }
95+ return state ;
96+ }
97+
8498 /**
8599 * @private
86100 * Checks if the current cursor position is inside the property name context
87101 * @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object} } context
88102 * @return {boolean } true if the context is in property name
89103 */
90104 function _isInPropName ( ctx ) {
91- var state ,
105+ var state = _getContextState ( ctx ) ,
92106 lastToken ;
93- if ( ! ctx || ! ctx . token || ! ctx . token . state || ctx . token . type === "comment" ) {
107+ if ( ! ctx || ! ctx . token || ctx . token . type === "comment" || ! state || ! state . context ) {
94108 return false ;
95109 }
96110
97- state = ctx . token . state . localState || ctx . token . state ;
98-
99- if ( ! state . context ) {
100- return false ;
101- }
102-
103111 lastToken = state . context . type ;
104112 return ( lastToken === "{" || lastToken === "rule" || lastToken === "block" ) ;
105113 }
@@ -124,16 +132,11 @@ define(function (require, exports, module) {
124132 return isInsideParens ( context . prev ) ;
125133 }
126134
127- var state ;
128- if ( ! ctx || ! ctx . token || ! ctx . token . state || ctx . token . type === "comment" ) {
135+ var state = _getContextState ( ctx ) ;
136+ if ( ! ctx || ! ctx . token || ctx . token . type === "comment" || ! state || ! state . context || ! state . context . prev ) {
129137 return false ;
130138 }
131139
132- state = ctx . token . state . localState || ctx . token . state ;
133-
134- if ( ! state . context || ! state . context . prev ) {
135- return false ;
136- }
137140 return ( ( state . context . type === "prop" &&
138141 ( state . context . prev . type === "rule" || state . context . prev . type === "block" ) ) ||
139142 isInsideParens ( state . context ) ) ;
@@ -146,14 +149,8 @@ define(function (require, exports, module) {
146149 * @return {boolean } true if the context is in property value
147150 */
148151 function _isInAtRule ( ctx ) {
149- var state ;
150- if ( ! ctx || ! ctx . token || ! ctx . token . state ) {
151- return false ;
152- }
153-
154- state = ctx . token . state . localState || ctx . token . state ;
155-
156- if ( ! state . context ) {
152+ var state = _getContextState ( ctx ) ;
153+ if ( ! ctx || ! ctx . token || ! state || ! state . context ) {
157154 return false ;
158155 }
159156 return ( state . context . type === "at" ) ;
@@ -1566,12 +1563,13 @@ define(function (require, exports, module) {
15661563 return selector ;
15671564 }
15681565
1569- var skipPrevSibling = false ;
1566+ var skipPrevSibling = false ,
1567+ state = _getContextState ( ctx ) ;
15701568
15711569 // If the cursor is inside a non-whitespace token with "block" or "top" state, then it is inside a
15721570 // selector. The only exception is when it is immediately after the '{'.
15731571 if ( isPreprocessorDoc && _hasNonWhitespace ( ctx . token . string ) && ctx . token . string !== "{" &&
1574- ( ctx . token . state . state === "block" || ctx . token . state . state === "top" ) ) {
1572+ ( state . state === "block" || state . state === "top" ) ) {
15751573 foundChars = true ;
15761574 }
15771575
@@ -1580,7 +1578,7 @@ define(function (require, exports, module) {
15801578 if ( ctx . token . type !== "comment" ) {
15811579 if ( ctx . token . string === "}" ) {
15821580 if ( isPreprocessorDoc ) {
1583- if ( ctx . token . state . state === "top" ) {
1581+ if ( state . state === "top" ) {
15841582 break ;
15851583 }
15861584 skipPrevSibling = true ;
0 commit comments