/// <summary> /// Creates a new inline source map /// </summary> /// <param name="wrapped"></param> /// <param name="mapBuilder"></param> /// <param name="sourceSourceMapType"></param> public V3DeferredSourceMap(V3SourceMap wrapped, StringBuilder mapBuilder, SourceMapType sourceSourceMapType) { if (wrapped == null) { throw new ArgumentNullException(nameof(wrapped)); } if (mapBuilder == null) { throw new ArgumentNullException(nameof(mapBuilder)); } _wrapped = wrapped; _mapBuilder = mapBuilder; SourceMapType = sourceSourceMapType; }
/// <summary> /// Adds a SourceMapAppender into the current bundle context if it doesn't already exist /// </summary> /// <param name="bundleContext"></param> /// <param name="sourceMapType"></param> /// <returns></returns> private void AddSourceMapAppenderToContext(BundleContext bundleContext, SourceMapType sourceMapType) { //if it already exist, then ignore var key = typeof(SourceMapDeclaration).Name; if (bundleContext.Items.TryGetValue(key, out object sm)) { return; } //not in the context so add a flag so it's not re-added bundleContext.Items[key] = "added"; bundleContext.AddAppender(() => { var sourceMap = bundleContext.GetSourceMapFromContext(sourceMapType); return(_sourceMapDeclaration.GetDeclaration(bundleContext, sourceMap)); }); }
/// <summary> /// Gets or Adds a V3InlineSourceMap into the current bundle context /// </summary> /// <param name="bundleContext"></param> /// <param name="sourceMapType"></param> /// <returns></returns> public static V3DeferredSourceMap GetSourceMapFromContext(this BundleContext bundleContext, SourceMapType sourceMapType) { var key = typeof(V3DeferredSourceMap).Name; object ctx; if (bundleContext.Items.TryGetValue(key, out ctx)) { return((V3DeferredSourceMap)ctx); } //not in the context so add it var sb = new StringBuilder(); var sourceMapWriter = new Utf8StringWriter(sb); var inlineSourceMap = new V3DeferredSourceMap((V3SourceMap)SourceMapFactory.Create(sourceMapWriter, V3SourceMap.ImplementationName), sb, sourceMapType); bundleContext.Items[key] = inlineSourceMap; return(inlineSourceMap); }