Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows user-defined functions to be reused across templates.
First, a function needs to be declared with an
@export()
decorator:Next, another template can import this function by name:
or as part of a namespace:
If the imported function uses user-defined types or calls other functions, those types and/or functions will be pulled into the importing template as part of the imported function's closure (but will not create symbols in the importing template's namespace unless they are explicitly imported).
To support importing functions from modules published to a registry, functions can also be imported from ARM JSON templates. User-defined functions in Bicep templates will always end up in the
__bicep
namespace and can be imported by the function name; user-defined functions in other namespaces may be imported using their fully qualified name (<namespace>.<function name>
) and must be aliased in the importing template. For example, given the following ARM JSON template:Both functions may be imported into a Bicep template (since both are marked as exportable) using the following syntax:
Because function symbols in Bicep need to implement a specific interface in order to be callable, this PR requires that imported symbols be distinguishable by C# type; therefore, the
ImportedSymbol
class has been replaced withImportedTypeSymbol
,ImportedVariableSymbol
,ImportedFunctionSymbol
, andErroredImportSymbol
. In order to make this distinction during the symbol declaration phase of compilation (when access to theISymbolContext
is blocked), a specialISemanticModelLookup
is passed to theDeclarationVisitor
that allows access semantic models other than the one being compiled. TheSourceFileGroupingBuilder
class blocks import cycles, so this is expected to be safe.Microsoft Reviewers: Open in CodeFlow