Skip to content

Commit c514b20

Browse files
coffeescript
1 parent 8c330dc commit c514b20

File tree

1 file changed

+54
-60
lines changed

1 file changed

+54
-60
lines changed

src/languages/coffeescript.js

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { insertBefore } from '../util/language-util.js';
21
import javascript from './javascript.js';
32

43
/** @type {import('../types.d.ts').LanguageProto<'coffeescript'>} */
54
export default {
65
id: 'coffeescript',
7-
require: javascript,
6+
base: javascript,
87
alias: 'coffee',
9-
grammar ({ extend }) {
8+
grammar () {
109
// Ignore comments starting with { to privilege string interpolation highlighting
1110
const comment = /#(?!\{).+/;
1211
const interpolation = {
1312
pattern: /#\{[^}]+\}/,
1413
alias: 'variable',
1514
};
1615

17-
const coffeescript = extend('javascript', {
16+
return {
1817
'comment': comment,
1918
'string': [
2019
// Strings are multiline
@@ -38,67 +37,62 @@ export default {
3837
pattern: /@(?!\d)\w+/,
3938
alias: 'variable',
4039
},
41-
});
42-
43-
insertBefore(coffeescript, 'comment', {
44-
'multiline-comment': {
45-
pattern: /###[\s\S]+?###/,
46-
alias: 'comment',
47-
},
48-
49-
// Block regexp can contain comments and interpolation
50-
'block-regex': {
51-
pattern: /\/{3}[\s\S]*?\/{3}/,
52-
alias: 'regex',
53-
inside: {
54-
'comment': comment,
55-
'interpolation': interpolation,
56-
},
57-
},
58-
});
59-
60-
insertBefore(coffeescript, 'string', {
61-
'inline-javascript': {
62-
pattern: /`(?:\\[\s\S]|[^\\`])*`/,
63-
inside: {
64-
'delimiter': {
65-
pattern: /^`|`$/,
66-
alias: 'punctuation',
40+
$insertBefore: {
41+
'comment': {
42+
'multiline-comment': {
43+
pattern: /###[\s\S]+?###/,
44+
alias: 'comment',
6745
},
68-
'script': {
69-
pattern: /[\s\S]+/,
70-
alias: 'language-javascript',
71-
inside: 'javascript',
46+
47+
// Block regexp can contain comments and interpolation
48+
'block-regex': {
49+
pattern: /\/{3}[\s\S]*?\/{3}/,
50+
alias: 'regex',
51+
inside: {
52+
'comment': comment,
53+
'interpolation': interpolation,
54+
},
7255
},
7356
},
74-
},
57+
'string': {
58+
'inline-javascript': {
59+
pattern: /`(?:\\[\s\S]|[^\\`])*`/,
60+
inside: {
61+
'delimiter': {
62+
pattern: /^`|`$/,
63+
alias: 'punctuation',
64+
},
65+
'script': {
66+
pattern: /[\s\S]+/,
67+
alias: 'language-javascript',
68+
inside: 'javascript',
69+
},
70+
},
71+
},
7572

76-
// Block strings
77-
'multiline-string': [
78-
{
79-
pattern: /'''[\s\S]*?'''/,
80-
greedy: true,
81-
alias: 'string',
73+
// Block strings
74+
'multiline-string': [
75+
{
76+
pattern: /'''[\s\S]*?'''/,
77+
greedy: true,
78+
alias: 'string',
79+
},
80+
{
81+
pattern: /"""[\s\S]*?"""/,
82+
greedy: true,
83+
alias: 'string',
84+
inside: {
85+
'interpolation': interpolation,
86+
},
87+
},
88+
],
8289
},
83-
{
84-
pattern: /"""[\s\S]*?"""/,
85-
greedy: true,
86-
alias: 'string',
87-
inside: {
88-
'interpolation': interpolation,
89-
},
90+
'keyword': {
91+
// Object property
92+
'property': /(?!\d)\w+(?=\s*:(?!:))/,
9093
},
91-
],
92-
});
93-
94-
insertBefore(coffeescript, 'keyword', {
95-
// Object property
96-
'property': /(?!\d)\w+(?=\s*:(?!:))/,
97-
});
98-
99-
delete coffeescript['doc-comment'];
100-
delete coffeescript['template-string'];
101-
102-
return coffeescript;
94+
},
95+
$delete: ['doc-comment', 'template-string'],
96+
};
10397
},
10498
};

0 commit comments

Comments
 (0)