123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- exports.activate = function () {
- if (!atom.grammars.addInjectionPoint) return;
- atom.grammars.addInjectionPoint('source.js', {
- type: 'call_expression',
- language(callExpression) {
- const { firstChild } = callExpression;
- switch (firstChild.type) {
- case 'identifier':
- return languageStringForTemplateTag(firstChild.text);
- case 'call_expression':
- return languageStringForTemplateTag(firstChild.children[0].text);
- case 'member_expression':
- if (firstChild.startPosition.row === firstChild.endPosition.row) {
- return languageStringForTemplateTag(firstChild.text);
- }
- }
- },
- content(callExpression) {
- const { lastChild } = callExpression;
- if (lastChild.type === 'template_string') {
- return stringFragmentsOfTemplateString(lastChild);
- }
- }
- });
- atom.grammars.addInjectionPoint('source.js', {
- type: 'assignment_expression',
- language(expression) {
- const { firstChild } = expression;
- if (firstChild.type === 'member_expression') {
- if (firstChild.lastChild.text === 'innerHTML') {
- return 'html';
- }
- }
- },
- content(expression) {
- const { lastChild } = expression;
- if (lastChild.type === 'template_string') {
- return stringFragmentsOfTemplateString(lastChild);
- }
- }
- });
- atom.grammars.addInjectionPoint('source.js', {
- type: 'regex_pattern',
- language() {
- return 'js-regex';
- },
- content(regex) {
- return regex;
- },
- languageScope: null
- });
- atom.grammars.addInjectionPoint('source.js', {
- type: 'comment',
- language(comment) {
- if (comment.text.startsWith('/**')) return 'jsdoc';
- },
- content(comment) {
- return comment;
- },
- languageScope: null,
- coverShallowerScopes: true
- });
- };
- exports.consumeHyperlinkInjection = (hyperlink) => {
- hyperlink.addInjectionPoint('source.js', {
- types: ['comment', 'template_string', 'string_fragment']
- });
- };
- exports.consumeTodoInjection = (todo) => {
- todo.addInjectionPoint('source.js', { types: ['comment'] });
- };
- const CSS_REGEX = /\bstyled\b|\bcss\b/i;
- const GQL_REGEX = /\bgraphql\b|\bgql\b/i;
- const SQL_REGEX = /\bsql\b/i;
- function languageStringForTemplateTag(tag) {
- if (CSS_REGEX.test(tag)) {
- return 'CSS';
- } else if (GQL_REGEX.test(tag)) {
- return 'GraphQL';
- } else if (SQL_REGEX.test(tag)) {
- return 'SQL';
- } else {
- return tag;
- }
- }
- function stringFragmentsOfTemplateString(templateStringNode) {
- return templateStringNode.children.filter(
- c => c.type === 'string_fragment'
- );
- }
|