Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2cc4660

Browse files
authoredFeb 2, 2022
Core: Added better error message for missing grammars (#3311)
1 parent 3f8cc5a commit 2cc4660

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed
 

‎components/prism-core.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,9 @@ var Prism = (function (_self) {
659659
language: language
660660
};
661661
_.hooks.run('before-tokenize', env);
662+
if (!env.grammar) {
663+
throw new Error('The language "' + env.language + '" has no grammar.');
664+
}
662665
env.tokens = _.tokenize(env.code, env.grammar);
663666
_.hooks.run('after-tokenize', env);
664667
return Token.stringify(_.util.encode(env.tokens), env.language);

‎components/prism-core.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/Prism.hooks.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h2>
7373

7474
<dt class="tag-source">Source:</dt>
7575
<dd class="tag-source"><ul class="dummy"><li>
76-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line714">line 714</a>
76+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line717">line 717</a>
7777
</li></ul></dd>
7878

7979

@@ -152,7 +152,7 @@ <h4 class="name" id=".add"><span class="type-signature">(static) </span>add<span
152152

153153
<dt class="tag-source">Source:</dt>
154154
<dd class="tag-source"><ul class="dummy"><li>
155-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line729">line 729</a>
155+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line732">line 732</a>
156156
</li></ul></dd>
157157

158158

@@ -314,7 +314,7 @@ <h4 class="name" id=".run"><span class="type-signature">(static) </span>run<span
314314

315315
<dt class="tag-source">Source:</dt>
316316
<dd class="tag-source"><ul class="dummy"><li>
317-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line746">line 746</a>
317+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line749">line 749</a>
318318
</li></ul></dd>
319319

320320

‎docs/Prism.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ <h4 class="name" id=".tokenize"><span class="type-signature">(static) </span>tok
12441244

12451245
<dt class="tag-source">Source:</dt>
12461246
<dd class="tag-source"><ul class="dummy"><li>
1247-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line691">line 691</a>
1247+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line694">line 694</a>
12481248
</li></ul></dd>
12491249

12501250

‎docs/Token.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ <h4 class="name" id="Token"><span class="type-signature"></span>new Token<span c
8080

8181
<dt class="tag-source">Source:</dt>
8282
<dd class="tag-source"><ul class="dummy"><li>
83-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line780">line 780</a>
83+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line783">line 783</a>
8484
</li></ul></dd>
8585

8686

@@ -364,7 +364,7 @@ <h4 class="name" id="alias"><span class="type-signature"></span>alias<span class
364364

365365
<dt class="tag-source">Source:</dt>
366366
<dd class="tag-source"><ul class="dummy"><li>
367-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line807">line 807</a>
367+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line810">line 810</a>
368368
</li></ul></dd>
369369

370370

@@ -447,7 +447,7 @@ <h4 class="name" id="content"><span class="type-signature"></span>content<span c
447447

448448
<dt class="tag-source">Source:</dt>
449449
<dd class="tag-source"><ul class="dummy"><li>
450-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line799">line 799</a>
450+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line802">line 802</a>
451451
</li></ul></dd>
452452

453453

@@ -524,7 +524,7 @@ <h4 class="name" id="type"><span class="type-signature"></span>type<span class="
524524

525525
<dt class="tag-source">Source:</dt>
526526
<dd class="tag-source"><ul class="dummy"><li>
527-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line790">line 790</a>
527+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line793">line 793</a>
528528
</li></ul></dd>
529529

530530

‎docs/global.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ <h4 class="name" id="Grammar">Grammar</h4>
143143

144144
<dt class="tag-source">Source:</dt>
145145
<dd class="tag-source"><ul class="dummy"><li>
146-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1236">line 1236</a>
146+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1239">line 1239</a>
147147
</li></ul></dd>
148148

149149

@@ -274,7 +274,7 @@ <h4 class="name" id="GrammarToken">GrammarToken</h4>
274274

275275
<dt class="tag-source">Source:</dt>
276276
<dd class="tag-source"><ul class="dummy"><li>
277-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1215">line 1215</a>
277+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1218">line 1218</a>
278278
</li></ul></dd>
279279

280280

@@ -559,7 +559,7 @@ <h4 class="name" id="HighlightCallback"><span class="type-signature"></span>High
559559

560560
<dt class="tag-source">Source:</dt>
561561
<dd class="tag-source"><ul class="dummy"><li>
562-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1244">line 1244</a>
562+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1247">line 1247</a>
563563
</li></ul></dd>
564564

565565

@@ -713,7 +713,7 @@ <h4 class="name" id="HookCallback"><span class="type-signature"></span>HookCallb
713713

714714
<dt class="tag-source">Source:</dt>
715715
<dd class="tag-source"><ul class="dummy"><li>
716-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1254">line 1254</a>
716+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line1257">line 1257</a>
717717
</li></ul></dd>
718718

719719

@@ -859,7 +859,7 @@ <h4 class="name" id="TokenStream">TokenStream</h4>
859859

860860
<dt class="tag-source">Source:</dt>
861861
<dd class="tag-source"><ul class="dummy"><li>
862-
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line812">line 812</a>
862+
<a href="prism-core.js.html">prism-core.js</a>, <a href="prism-core.js.html#line815">line 815</a>
863863
</li></ul></dd>
864864

865865

‎docs/prism-core.js.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@ <h1 class="page-title">prism-core.js</h1>
712712
language: language
713713
};
714714
_.hooks.run('before-tokenize', env);
715+
if (!env.grammar) {
716+
throw new Error('The language "' + env.language + '" has no grammar.');
717+
}
715718
env.tokens = _.tokenize(env.code, env.grammar);
716719
_.hooks.run('after-tokenize', env);
717720
return Token.stringify(_.util.encode(env.tokens), env.language);

‎prism.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ var Prism = (function (_self) {
664664
language: language
665665
};
666666
_.hooks.run('before-tokenize', env);
667+
if (!env.grammar) {
668+
throw new Error('The language "' + env.language + '" has no grammar.');
669+
}
667670
env.tokens = _.tokenize(env.code, env.grammar);
668671
_.hooks.run('after-tokenize', env);
669672
return Token.stringify(_.util.encode(env.tokens), env.language);

0 commit comments

Comments
 (0)
Please sign in to comment.