@@ -30,12 +30,69 @@ import {
3030
3131import { resolveSchema } from "./resolve.ts" ;
3232
33- import { MappedString } from "../text-types.ts" ;
34- import { createLocalizedError } from "./errors.ts" ;
33+ import { MappedString , StringMapResult } from "../text-types.ts" ;
34+ import { createLocalizedError , createSourceContext } from "./errors.ts" ;
3535import { InternalError } from "../error.ts" ;
36+ import { mappedIndexToLineCol } from "../mapped-text.ts" ;
37+ import { TidyverseError } from "../errors-types.ts" ;
3638
3739////////////////////////////////////////////////////////////////////////////////
3840
41+ function createNiceError ( obj : {
42+ violatingObject : AnnotatedParse ;
43+ source : MappedString ;
44+ message : string ;
45+ } ) : TidyverseError {
46+ const {
47+ violatingObject,
48+ source,
49+ message,
50+ } = obj ;
51+ const locF = mappedIndexToLineCol ( source ) ;
52+
53+ let location ;
54+ try {
55+ location = {
56+ start : locF ( violatingObject . start ) ,
57+ end : locF ( violatingObject . end ) ,
58+ } ;
59+ } catch ( _e ) {
60+ location = {
61+ start : { line : 0 , column : 0 } ,
62+ end : { line : 0 , column : 0 } ,
63+ } ;
64+ }
65+
66+ const mapResult = source . map ( violatingObject . start ) ;
67+ const fileName = mapResult ? mapResult . originalString . fileName : undefined ;
68+ return {
69+ heading : message ,
70+ error : [ ] ,
71+ info : { } ,
72+ fileName,
73+ location : location ! ,
74+ sourceContext : createSourceContext ( violatingObject . source , {
75+ start : violatingObject . start ,
76+ end : violatingObject . end ,
77+ } ) ,
78+ } ;
79+ }
80+
81+ export class NoExprTag extends Error {
82+ constructor ( violatingObject : AnnotatedParse , source : MappedString ) {
83+ super ( `Unexpected !expr tag` ) ;
84+ this . name = "NoExprTag" ;
85+ this . niceError = createNiceError ( {
86+ violatingObject,
87+ source,
88+ message :
89+ "!expr tags are not allowed in Quarto outside of knitr code cells." ,
90+ } ) ;
91+ }
92+
93+ niceError : TidyverseError ;
94+ }
95+
3996class ValidationContext {
4097 instancePath : ( number | string ) [ ] ;
4198 root : ValidationTraceNode ;
@@ -561,6 +618,12 @@ function validateObject(
561618 }
562619 }
563620 }
621+ if (
622+ value . result && typeof value . result === "object" &&
623+ ! Array . isArray ( value . result ) && value . result ?. tag === "!expr"
624+ ) {
625+ throw new NoExprTag ( value , value . source ) ;
626+ }
564627 throw new InternalError ( `Couldn't locate key ${ key } ` ) ;
565628 } ;
566629 const inspectedProps : Set < string > = new Set ( ) ;
0 commit comments