Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Allow CSS injection inside 'styled' tagged template literals
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Oct 30, 2018
1 parent 61cc764 commit a2f66fc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ exports.activate = function () {
const {firstChild} = callExpression
switch (firstChild.type) {
case 'identifier':
return firstChild.text
return languageStringForTemplateTag(firstChild.text)
case 'member_expression':
if (firstChild.startPosition.row === firstChild.endPosition.row) {
return firstChild.text
return languageStringForTemplateTag(firstChild.text)
}
}
},
Expand Down Expand Up @@ -50,3 +50,13 @@ exports.activate = function () {
content (regex) { return regex }
})
}

const STYLED_REGEX = /\bstyled\b/i

function languageStringForTemplateTag (tag) {
if (STYLED_REGEX.test(tag)) {
return 'CSS'
} else {
return tag
}
}

0 comments on commit a2f66fc

Please sign in to comment.